代码之家  ›  专栏  ›  技术社区  ›  Tim Büthe

为什么UIActionSheet取消会使我的应用程序崩溃?

  •  1
  • Tim Büthe  · 技术社区  · 16 年前

    - (void) doItWithConfirm {
    
        UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"do you really wanna do it?" 
                                delegate:self cancelButtonTitle:@"I don't" destructiveButtonTitle: nil
                                otherButtonTitles:@"Yes, do it", nil];
    
        [actionSheet showInView:self.view];
        [actionSheet release];
    }
    
    - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    
        NSLog(@"buttonIndex: %@", buttonIndex);
    }
    
    1 回复  |  直到 16 年前
        1
  •  4
  •   kennytm    16 年前
    NSLog(@"buttonIndex: %@", buttonIndex);
    

    %@ 只需要ObjC对象(不是整数)。这种不匹配会导致系统崩溃。使用

    NSLog(@"buttonIndex: %d", buttonIndex);