易开关案例问题.... [客观问题]

Phi*_*hil 2 iphone objective-c switch-statement

如果注释nslog-line,则会出错:

语义问题:使用未声明的标识符'alert'

switch ([[array objectAtIndex:0]intValue]) {
    case 2:
        NSLog(@"Allergie alarm");   << commenting this, gives me an error!!!
        UIAlertView *alert = [[UIAlertView alloc]
                              initWithTitle: @"blabal"
                              message: @"balbalb"
                              delegate: nil
                              cancelButtonTitle:@"OK"
                              otherButtonTitles:nil, nil];
        [alert show];
        [alert release];
        break;
    default:
        break;
}
Run Code Online (Sandbox Code Playgroud)

Dar*_*ust 7

为了在case你需要打开一个新范围内声明一个新变量.要打开一个新的范围,只需使用花括号,就像其他人已经写过的那样.