当用户点击按钮时,在我的iOS应用程序中以操作表单的形式呈现了一个UIAlertController。
一切都很好,除了一个问题,完成块由于某种原因没有被调用。
这是我的代码:
// 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,那么它就会运行...为什么?感谢您的时间,丹。