Sup*_*off 13 cocoa-touch objective-c uiactionsheet ios uialertcontroller
当用户点击按钮时,我的应用程序中会显示一个带有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];
Run Code Online (Sandbox Code Playgroud)
如果您运行该代码,您将看到解除控制器不会运行的行,并且NSLog
它内部的语句也不会.但是,如果你删除NSLog
并将完成块设置为nil,那么它确实运行....为什么???
谢谢你的时间,丹.
rma*_*ddy 44
请勿尝试关闭警报控制器.在调用警报操作的处理程序时,它将被解雇.
将"取消"操作更改为:
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"Dismiss" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {
NSLog(@"asdhfgjk");
}];
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7650 次 |
最近记录: |