为什么开关大小写不需要多行,如果做得很好
if(indexPath.row == 1){
UIViewController *viewController = [UIViewController new];
viewController.view.backgroundColor = [UIColor whiteColor];
viewController.title = _titlesArray[indexPath.row];
[self.navigationController pushViewController:viewControlleranimated:YES];
}无法在switch语句中使用的相同代码
switch (indexPath.row) {
case 0:
UIViewController *viewController = [UIViewController new];
viewController.view.backgroundColor = [UIColor whiteColor];
viewController.title = _titlesArray[indexPath.row];
[self.navigationController pushViewController:viewControlleranimated:YES];
break;
case 1:
break;
default
break:
}在开关语句中,它给出了一个错误..。我强制使用if else语句来安装开关箱。有谁能建议我如何使用开关案例的状态。
发布于 2015-11-28 11:39:35
只要没有变量定义,开关将占用多行。任何新的定义都需要附上。因此,这两者都是有效的:
case 0:
{
UIViewController *viewController = [UIViewController new];
viewController.view.backgroundColor = [UIColor whiteColor];
viewController.title = _titlesArray[indexPath.row];
[self.navigationController pushViewController:viewControlleranimated:YES];
break;
}和
UIViewController *viewController;
...
case 0:
viewController = [UIViewController new];
viewController.view.backgroundColor = [UIColor whiteColor];
viewController.title = _titlesArray[indexPath.row];
[self.navigationController pushViewController:viewControlleranimated:YES];
break;https://stackoverflow.com/questions/33970872
复制相似问题