关于UIAlertView 的 dismissWithClickedButtonIndex: animated: 后台执行的问题

在项目中遇到这样的问题,当我在后台执行UIAlertView 的 dismissWithClickedButtonIndex: animated:  方法时,程序崩溃,未给出任何崩溃日志;

各种测试研究后得到解决方法,就是把dismissWithClickedButtonIndex: animated: 手动强制放到主线程中执行,如下:

[self performSelectorOnMainThread:@selector(dismissAlertView) withObject:nil waitUntilDone:NO];

- (void)dismissAlertView{
    [syncAlertView dismissWithClickedButtonIndex:0 animated:NO];
    syncAlertView = nil;
}

分析原因可能是:当程序在后台时,其当前线程并不是主线程,而关于UI的处理必须在主线程中执行,所以会发生崩溃



你可能感兴趣的:(Objective-C,后台)