我在提示用户
时收到以下异常0 CoreFoundation __exceptionPreprocess + 130
1 libobjc.A.dylib objc_exception_throw + 38
2 CoreFoundation -[NSObject(NSObject) doesNotRecognizeSelector:] + 202
3 CoreFoundation ___forwarding___ + 706
4 CoreFoundation _CF_forwarding_prep_0 + 24
5 UIKit -[_UIModalItem setMessage:] + 40
6 UIKit -[_UIModalItem initWithTitle:message:otherButtonTitles:completion:delegate:] + 102
7 UIKit +[_UIModalItem modalItemWithType:title:message:buttonTitles:completion:] + 76
8 UIKit -[UIAlertView _modalItemForNeueCompatibility] + 362
9 UIKit -[UIAlertView popupAlertAnimated:animationType:atOffset:] + 56
10 UIKit -[UIAlertView popupAlertAnimated:animationType:] + 34
我在一个实用程序类
中的方法中编写了Alert视图代码+(void)showAlertWithTitle:(NSString*)title message:(NSString*)msg cancelButtonTitle:(NSString*)canceltitle confirmBtnTitle:(NSString*)cnftitle andTag:(int)alertTag andDelegate:(id)ref{
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:title message:msg delegate:ref cancelButtonTitle:canceltitle otherButtonTitles:cnftitle, nil];
alertView.tag = alertTag;
[alertView show];
}
答案 0 :(得分:-1)
您必须从主线程显示警报视图。如果可以从任何其他队列或线程调用这段代码,请将其包装在对dispatch_async的调用中:
dispatch_async(dispatch_get_main_queue(), ^
{
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:title message:msg delegate:ref cancelButtonTitle:canceltitle otherButtonTitles:cnftitle, nil];
alertView.tag = alertTag;
[alertView show];
});