Block for UIAlertViewDelegate

前端 未结 11 1507
悲哀的现实
悲哀的现实 2020-12-23 12:15

I\'m pretty new to objective C and I\'m just trying to figure out if I can use a block or a selector as the UIAlertViewDelegate argument for UIAlertView - and which is more

11条回答
  •  南方客
    南方客 (楼主)
    2020-12-23 12:57

    I had to edit the calling example a bit to stop complier error. Just a small tweak and xcode was happy.

    UIAlertViewBlock *alert = [[UIAlertViewBlock alloc] initWithTitle:@"hi"
                                                              message:@"hi there"
                                                           completion:^(BOOL canceled,NSInteger buttonIndex) {
                                                               NSLog(@"canceled=%d", canceled);
                                                               NSLog(@"pressed=%d", buttonIndex);
                                                           }
                                                   cancelButtonTitle:@"cancel"
                                                    otherButtonTitles:@"ok", nil];
    [alert show];
    

提交回复
热议问题