【发布时间】:2015-06-15 19:24:32
【问题描述】:
我有一个带有 UIAlertController 的 iOS 应用程序,当用户点击按钮时,我的应用程序中会以操作表的形式呈现。
这一切都很好,除了一件事,完成块由于某种原因没有被调用。
这是我的代码:
// Setup the alert information/type.
UIAlertController *action_view = [UIAlertController alertControllerWithTitle:@"Test title" message:@"test message" preferredStyle:UIAlertControllerStyleActionSheet];
// Create and add the cancel button.
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"Dismiss" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {
[action_view dismissViewControllerAnimated:YES completion:^{
NSLog(@"asdhfgjk");
}];
}];
// Add the action button to the alert.
[action_view addAction:cancel];
// Present the alert to the user.
[self presentViewController:action_view animated:YES completion:nil];
如果您运行该代码,您将看到关闭控制器的行不会运行,其中的 NSLog 语句也不会运行。但是,如果您删除 NSLog 并将完成块设置为 nil,那么它确实会运行....为什么???
感谢您的宝贵时间,丹。
【问题讨论】:
标签: ios objective-c cocoa-touch uiactionsheet uialertcontroller