SAH*_*AHM 5 modal-dialog objective-c uiviewcontroller ios8 uialertcontroller
在iOS 8之前,可以在UIViewController被解除的同时从模式呈现的UIViewController中显示UIAlertView.我发现当用户需要提醒他们按下模态控制器上的"保存"按钮时发生的某些变化时,这一点特别有用.从iOS 8开始,如果UIAlertController在被取消时从模态呈现的视图控制器中显示,则UIAlertController也被解除.UIAlertController在用户可以阅读或自行解雇之前被解雇.我知道,一旦控制器被解除,我可以为模态控制器显示警报视图,但是这种情况会产生大量的额外工作,因为这个控制器在许多地方使用,并且必须向UIAlertController提供某些条件,要求在每种情况下将参数传递回控制器代表.有没有办法在控制器被解除的同时从模态呈现的控制器(或至少从控制器内的代码)显示UIAlertController,并让UIAlertController保持不变直到它被解除?
小智 2
您可以在模态控制器类的missViewControllerAnimated 方法的完成块中处理此问题。在 rootviewcontroller 上呈现 UIAlertController,它应该在任何类中处理。
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self.navigationItem.rightBarButtonItem setAction:@selector(dismissView)];
[self.navigationItem.rightBarButtonItem setTarget:self];
}
- (void)dismissView {
[self dismissViewControllerAnimated:YES completion:^{
[self showAlert];
}];
}
- (void)showAlert {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Alert" message:@"This is Alert" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okButton = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
[alertController dismissViewControllerAnimated:YES completion:nil];
}];
UIAlertAction *cancelButton = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
[alertController dismissViewControllerAnimated:YES completion:nil];
}];
[alertController addAction:okButton];
[alertController addAction:cancelButton];
UIViewController *rootViewController=[UIApplication sharedApplication].delegate.window.rootViewController;
[rootViewController presentViewController:alertController animated:YES completion:nil];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2810 次 |
| 最近记录: |