我的应用程序崩溃了,一定是因为UIAlertController。
此问题仅在可使用UIAlertController的iOS 8.x上出现。奇怪的是,我的应用程序既不使用UIAlertViewController,也不使用UIAlertView。
报告告诉我:
Trying to dismiss UIAlertController <UIAlertController: 0x172c5d80> with unknown presenter.
这怎么会发生呢?
我想过
当提示或通用对话框仍在屏幕上时,
但这些案子都没能把我送到车祸现场。
崩溃日志告诉我的事实是,操作系统显示了一个将附加到我的应用程序窗口的AlertView,在某些情况下,它会使呈现该UIAlertViewController的父视图控制器松散。
有什么办法可以找到这个问题吗?
这里是堆栈跟踪
_________________________________
0 CoreFoundation 0x2bc0c45f __exceptionPreprocess + 127
1 libobjc.A.dylib 0x39c79c8b objc_exception_throw + 36
2 CoreFoundation 0x2bc0c3a5 +[NSException raise:format:] + 110
3 UIKit 0x2f4ad13d -[UIAlertController _dismissAnimated:triggeringAction:triggeredByPopoverDimmingView:] + 414
4 UIKit 0x2f4acf97 -[UIAlertController _dismissAnimated:triggeringAction:] + 28
5 UIKit 0x2f590a0b -[_UIAlertControllerActionView touchesEnded:withEvent:] + 160
6 UIKit 0x2f159567 -[UIWindow _sendTouchesForEvent:] + 520
7 UIKit 0x2f152e31 -[UIWindow sendEvent:] + 542
8 UIKit 0x2f129759 -[UIApplication sendEvent:] + 194
9 UIKit 0x2f39d2f9 _UIApplicationHandleEventFromQueueEvent + 14166
10 UIKit 0x2f1281a9 _UIApplicationHandleEventQueue + 1350
11 CoreFoundation 0x2bbd2fbf __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 12
12 CoreFoundation 0x2bbd23cf __CFRunLoopDoSources0 + 216
13 CoreFoundation 0x2bbd0a35 __CFRunLoopRun + 770
14 CoreFoundation 0x2bb1e3b1 CFRunLoopRunSpecific + 474
15 CoreFoundation 0x2bb1e1c3 CFRunLoopRunInMode + 104
16 GraphicsServices 0x3308d201 GSEventRunModal + 134
17 UIKit 0x2f18843d UIApplicationMain + 1438
18 MyApp 0x00028a07 main (main.mm:16)
编辑
黑洞询问我的窗口初始化。下面是我的AppDelegate的代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[MyAppCustomWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
_mainViewController = [[MyAppContainerViewController alloc] initWithNibName:nil bundle:nil];
_mainStatusBarVC = [[MyAppStatusBarVC alloc] initWithRootVC:_mainViewController];
[self.window setRootViewController:_mainStatusBarVC];
[self.window makeKeyAndVisible];
return YES;
}
发布于 2015-09-01 00:04:49
我敢打赌你的车祸发生在iPad上。
在来自iOS8的iPad上,UIActionSheet似乎是通过UIAlertController
来处理的
使用此代码,
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if(buttonIndex == 1) return; // Cancel button
[self doSomeViewControllerDismisses];
}
我的应用程序崩溃了,和你得到的错误一样。
为了防止这种情况,我只是在下一次MainThread执行时调度复杂的dismiss调用,以便给隐藏的UIAlertViewController
一个适当释放的机会。
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if(buttonIndex == 1) return; // Cancel button
dispatch_async(dispatch_get_main_queue(), ^{
[self doSomeViewControllerDismisses];
});
}
发布于 2015-04-24 05:10:59
此表单的堆栈跟踪通常表示您已从UIViewController导航离开,而您已将其显示的警报仍未显示。
解决这个问题的一般方法是在UIAlertViewDelegate的alertView:didDismissWithButtonIndex:方法中呈现或取消控制器,因为这样您就可以确定在任何取消期间呈现者不会消失。
在您的情况下,如果您找不到任何可重现的情况,您可以尝试在呈现/关闭控制器之前检查presentedViewController,看看这是否会有什么结果。
但是,如果您检查您的控制器转换,您可能会发现,响应系统警报可能会以编程方式触发导航。你有没有什么功能可以抛出一个系统警报给用户授权,比如访问照片或任何东西,而他们拒绝它会导致控制器被你的错误处理以编程方式解除?这似乎是一个合理的合理的方案。
发布于 2015-08-26 19:35:05
尝试在主线程Alertview上取消使用Block on main thrad。
dispatch_async(dispatch_get_main_queue(), { () -> Void in
// Write your alert view code in swift language .
})
https://stackoverflow.com/questions/29649223
复制相似问题