Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 简易开关箱问题。。。。[目标c]_Iphone_Objective C_Switch Statement - Fatal编程技术网

Iphone 简易开关箱问题。。。。[目标c]

Iphone 简易开关箱问题。。。。[目标c],iphone,objective-c,switch-statement,Iphone,Objective C,Switch Statement,如果注释nslog行,则出现错误: 语义问题:使用未声明的 标识符“警报” 开关([[array objectAtIndex:0]intValue]){ 案例2: NSLog(@“过敏警报”);设置警报的委托 UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"blabal" message: @"balbal

如果注释nslog行,则出现错误:

语义问题:使用未声明的 标识符“警报”

开关([[array objectAtIndex:0]intValue]){
案例2:
NSLog(@“过敏警报”);设置警报的委托

 UIAlertView *alert = [[UIAlertView alloc]
                              initWithTitle: @"blabal"
                              message: @"balbalb"
                              delegate: self
                              cancelButtonTitle:@"OK"
                              otherButtonTitles:nil, nil];
问候,, Shyam

使用下面的

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;
}
开关([[array objectAtIndex:0]intValue]){
案例2:
{
NSLog(@“过敏报警”);
案例2:
{

NSLog(@“Allergie alarm”);您正在使用多行case语句。您的语句必须包含在
{
}
中。因此:

case 2: {
    NSLog(@"Allergie alarm");
    UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle: @"blabal"
                          message: @"balbalb"
                          delegate: nil
                          cancelButtonTitle:@"OK"
                          otherButtonTitles:nil, nil];
    [alert show];
    [alert release];
    break;
}

您不应该在开关内声明变量

这样试试

UIAlertView *alert;
switch ([[array objectAtIndex:0]intValue]) {
    case 2:

    alert = [[UIAlertView alloc]
                              initWithTitle: @"blabal"
                              message: @"balbalb"
                              delegate: nil
                              cancelButtonTitle:@"OK"
                              otherButtonTitles:nil, nil];
        [alert show];
        [alert release];
        break;
    default:
        break;
}
或者把它放在支架里

    case 2:
    {
    UIAlertView * alert = [[UIAlertView alloc]
                              initWithTitle: @"blabal"
                              message: @"balbalb"
                              delegate: nil
                              cancelButtonTitle:@"OK"
                              otherButtonTitles:nil, nil];
        [alert show];
        [alert release];
        break;
    default:
        break;
    }

要在
案例中声明新变量,您需要打开一个新范围。要打开一个新范围,只需像其他人已经编写的那样使用大括号。

///一些代码
////some code
switch ([[array objectAtIndex:0]intValue]) {
  case 2:
    NSLog(@"Allergie alarm");   << commenting this, gives me an error!!!
    [self showAlert];
    break;
default:
    break;
}
////some code




- (void) showAlert{
    UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle: @"blabal"
                          message: @"balbalb"
                          delegate: nil
                          cancelButtonTitle:@"OK"
                          otherButtonTitles:nil, nil];
    [alert show];
    [alert release];
  } 
开关([[array objectAtIndex:0]intValue]){ 案例2:
NSLog(@“Allergie alarm”);我认为问题不是像作用域一样的东西。问题是当他对NSLog语句进行注释时,然后编译器读取代码之类的东西

案例2:UIAlertView*警报

意味着认为这是案例2的一个参数。 我检查了这一点,案例二之后的第一行不应该是变量的声明行,这意味着它们的作用域不是问题

switch (2) {
     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];
         [alert show];
         [alert release];
         break;

     default:
         break;
 }
开关(2){
案例2:
;

//NSLog(@“Allergie alarm”);//添加一个方法并因此调用另一个方法来解决这个简单的问题不是一个好的解决方案,尽管它确实解决了问题。
////some code
switch ([[array objectAtIndex:0]intValue]) {
  case 2:
    NSLog(@"Allergie alarm");   << commenting this, gives me an error!!!
    [self showAlert];
    break;
default:
    break;
}
////some code




- (void) showAlert{
    UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle: @"blabal"
                          message: @"balbalb"
                          delegate: nil
                          cancelButtonTitle:@"OK"
                          otherButtonTitles:nil, nil];
    [alert show];
    [alert release];
  } 
switch (2) {
     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];
         [alert show];
         [alert release];
         break;

     default:
         break;
 }