cannot jump from switch statement to this case
2017-08-24 16:04
435 查看
用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;
}
}
查阅资料发现,是因为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;
}
}
相关文章推荐
- 关于cannot jump from switch statement to this case label的问题解决
- 错误信息:cannot jump from switch statement to this case
- 错误信息:Cannot jump from switch statement to this case
- cannot jump from switch statement to this case
- switch case语句里面不能定义对象 错误信息:Cannot jump from switch statement to this case..
- Type mismatch: cannot convert from java.sql.PreparedStatement to com.mysql.jdbc.PreparedStatement
- cannot convert 'this' pointer from 'const class Rational' to 'class Rational &' 是什么意思
- error C2440: ’static_cast’ : cannot convert from ‘UINT (__thiscall CStaticLink::* )(CPoint)’ to ‘LRE
- error C2440: 'static_cast' : cannot convert from 'void (__thiscall CMainFrame::* )(void)' to 'LRESU
- As of ADT 14, resource fields cannot be used ad switch cases. Invoke this fix to get more informatio
- error C2440: 'static_cast' : cannot convert from 'void (__thiscall CChatDlg::* )(WPARAM,LPARAM)' to
- error C2440: 'static_cast' : cannot convert from 'void (__thiscall CMainFrame::* )(void)' to 'LRESUL
- error C2440: 'static_cast' : cannot convert from 'void (__thiscall CTrunkPage::* )(void)' to 'void (__thiscall CCmdTarget::* )(N
- error C2440: 'static_cast' : cannot convert from 'void (__thiscall CChatDlg::* )(WPARAM,LPARAM)' to
- This document cannot be displayed while offline. To go online, uncheck Work Offline from the File me
- error C2440: 'static_cast' : cannot convert from 'LRESULT (__thiscall CchatDlg::* )(CPoint)' to 'UI
- error C2440: 'static_cast' : cannot convert from 'void (__thiscall CMainFrame::* )(void)' to 'LRESUL
- error C2440: 'static_cast' : cannot convert from 'void (__thiscall CMainFrame::* )(void)' to 'LRESUL
- switch语句中编程错误:jump to case label
- error C2440: 'static_cast' : cannot convert from 'void (__thiscall CMainFrame::* )(void)' to 'LRESUL