在iOS中的switch错误
在iOS中出现switch错误的原因是在switch语句中直接初始化UIAlertview。正确的做法是将它放在花括号中。解决方法是将初始化UIAlertview的代码放在花括号中。
代码示例:
switch (val) { case 10: { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:@"great!!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; [alertView show]; } break; }
请将NSLog放在UIALertView上方,你就会发现错误消失了。