【发布时间】:2014-05-05 15:32:07
【问题描述】:
我正在学习 switch 功能,所以我将 if 和 else 语句更改为这样:
但它给了我“预期的表达”错误。
为什么?
switch (indexPath.section) {
case 0: return {
cell.textLabel.text = FileANames[indexPath.row];
cell.detailTextLabel.text = FileADetails[FileANames[indexPath.row]];
}
case 1: return {
cell.textLabel.text = FileBNames[indexPath.row];
cell.detailTextLabel.text = FileBDetails[FileBNames[indexPath.row]];
}
case 2: return {
cell.textLabel.text = FileCNames[indexPath.row];
cell.detailTextLabel.text = FileCDetails[FileCNames[indexPath.row]];
}
default: return cell;
}
//这个是对的
if (indexPath.section == 0) {
cell.textLabel.text = FileANames[indexPath.row];
cell.detailTextLabel.text = FileADetails[FileANames[indexPath.row]];
}
else if (indexPath.section == 1) {
cell.textLabel.text = FileBNames[indexPath.row];
cell.detailTextLabel.text = FileBDetails[FileBNames[indexPath.row]];
}
else if (indexPath.section == 2) {
cell.textLabel.text = FileCNames[indexPath.row];
cell.detailTextLabel.text = FileCDetails[FileCNames[indexPath.row]];
}
return cell;
}
谢谢。
【问题讨论】:
-
不要这样
return。也可以break。 -
谢谢!现在可以了。
标签: objective-c if-statement switch-statement