在switch的case语句后,使用UIAlertView报错

错误提示如下:

分析:

      You are using multiline case statement. Your statements must be enclosed in { and }.

  The problem is declaring variables inside cases of a switch. The compiler is upset about trying to figure out scope when only some of the code is executed. If you put brackets around the contents of the 'fail' case, it should be OK since that restricts the scope.

修改方案:

1)不要在case 下声明变量

2)多个case下,可用{}将case中的代码括起来。

效果如下:

                case 2:{
                    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"
                                                                    message:@"验证码信息不正确,请重新获取验证码!"
                                                                   delegate:self
                                                          cancelButtonTitle:@"关闭"
                                                          otherButtonTitles:nil];
                    [alert show];
                    [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(dismissAlert:) userInfo:[NSDictionary dictionaryWithObjectsAndKeys:alert,@"alert", nil] repeats:NO];
                    [alert release];
                    break;
                } 
          case 3: ⋯⋯
原文地址:https://www.cnblogs.com/ygm900/p/2814523.html