美文网首页
iOS switch语句中为什么不能直接进行页面跳转

iOS switch语句中为什么不能直接进行页面跳转

作者: 小柴2011 | 来源:发表于2016-08-27 14:04 被阅读667次

没有复杂的逻辑 ,直接上代码。

switch (indexPath.row) {

case 0:

MyAccountViewController *myAccountVC = [[MyAccountViewController alloc]init];

[self.navigationController pushViewController:myAccountVC animated:YES];

break;

case 1:

MyorderViewController *MyorderVC = [[MyorderViewController alloc]init];

[self.navigationController pushViewController:MyorderVC animated:YES];

NSLog(@"服务订单");

break;

case 2:

NSLog(@"我的商品");

MyGoodsViewController *goodsViewController = [[MyGoodsViewController alloc]init];

[self.navigationController pushViewController:goodsViewController animated:YES];

break;

default:

break;

}


上面的代码Xcode会报错 ,解决方法是:在需要跳转的语句两端加上 {},如下引用部分。

switch (indexPath.row) {

case 0:

{

MyAccountViewController *myAccountVC = [[MyAccountViewController alloc]init];

[self.navigationController pushViewController:myAccountVC animated:YES];

}

break;

case 1:

{

MyorderViewController *MyorderVC = [[MyorderViewController alloc]init];

[self.navigationController pushViewController:MyorderVC animated:YES];

NSLog(@"服务订单");

}

break;

case 2:

{

NSLog(@"我的商品");

MyGoodsViewController *goodsViewController = [[MyGoodsViewController alloc]init];

[self.navigationController pushViewController:goodsViewController animated:YES];

}

break;

default:

break;

}

相关文章

网友评论

      本文标题:iOS switch语句中为什么不能直接进行页面跳转

      本文链接:https://www.haomeiwen.com/subject/isftettx.html