iOS8开始使用UIAlertController
今天遇到一个问题,效果是展示一个alert 之后消失
在iOS8中崩溃
崩溃信息:
Trying to dismiss the presentation controller while transitioning already. (<_UIAlertControllerAlertPresentationController: 0x78feff20>)
transitionViewForCurrentTransition is not set, presentation controller was dismissed during the presentation? (<_UIAlertControllerAlertPresentationController: 0x78feff20>)
这是写的代码
UIAlertController* vc = [UIAlertController alertControllerWithTitle:message message:nil preferredStyle:UIAlertControllerStyleAlert];
[target presentViewController:vc animated:YES completion:^{
[vc dismissViewControllerAnimated:YES completion:NULL];
}];
后来发现需要这样写问题解决
UIAlertController* vc = [UIAlertController alertControllerWithTitle:message message:nil preferredStyle:UIAlertControllerStyleAlert];
[target presentViewController:vc animated:YES completion:^{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[vc dismissViewControllerAnimated:YES completion:NULL];
});
}];
本文介绍了在iOS8中使用UIAlertController时遇到的一个具体问题及解决方案。当尝试在展示后立即关闭UIAlertController时会触发崩溃,通过延迟执行dismiss操作解决了该问题。
299

被折叠的 条评论
为什么被折叠?



