当 modalView 出现时,网络事件会生成一个新的模态视图控制器。我正在做的是将 presentViewController:animated 链接到dismissViewControllerAnimated:completion 中,如下所示:
// ModalViewController *vc = ...
if (self.presentedViewController) {
__weak MyViewController *me = self;
[self.presentedViewController dismissViewControllerAnimated:YES
completion:
^{
// need a delay to call?
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[me presentViewController:vc
animated:YES
completion:nil];
});
}];
}else{
[self presentViewController:vc animated:YES completion:nil];
}
一切顺利:最初的模态视图控制器被关闭,网络生成的视图控制器呈现,用户可以成功关闭它。但是,当尝试呈现第三个 modalViewController 时,它失败并出现错误:
2014-03-26 15:49:52.111 coshop[6046:60b] Warning: Attempt to dismiss from view controller <RootViewController: 0xa8b54a0> while a presentation or dismiss is in progress!
我也试过这个:
if (self.presentedViewController) {
__weak MyViewController *me = self;
[self.presentedViewController dismissViewControllerAnimated:YES
completion:nil];
// dismiss animation ends within 0.5.
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[me presentViewController:vc
animated:YES
completion:nil];
});
}else{
[self presentViewController:vc animated:YES completion:nil];
}
有什么建议吗?谢谢!