用switch case出现了一个错误,cannot jump from switch statement to this case....
查阅资料发现,是因为switch case 中是不能定义对象的,因为只要是在大括号内定义的对象
例如 switch (doBtn.tag) {
case 107:
NSLog(@"结束");
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"确定要结束当前的活动吗" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
//响应事件
[self endActivityRequest];
}];
UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
//响应事件
return ;
}];
[alert addAction:defaultAction];
[alert addAction:cancelAction];
[self presentViewController:alert animated:YES completion:nil];
break;
}这样就报错,只要加上一个大括号即可以
switch (doBtn.tag) {
case 107:
{
NSLog(@"结束");
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"确定要结束当前的活动吗" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
//响应事件
[self endActivityRequest];
}];
UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
//响应事件
return ;
}];
[alert addAction:defaultAction];
[alert addAction:cancelAction];
[self presentViewController:alert animated:YES completion:nil];
break;
}
}