Ios 视图崩溃

Ios 视图崩溃,ios,objective-c,uialertview,Ios,Objective C,Uialertview,我在提示用户时收到以下异常 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_f

我在提示用户时收到以下异常

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
我在一个实用程序类的方法中编写了警报视图代码

+(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];
}

必须从主线程显示警报视图。如果这段代码可能会从任何其他队列或线程调用,请将其包装在对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];
});

我实现了相同的代码,它工作得很好。您是否为objective-c异常设置了断点?警报解除时是否存在
ref
?实际上,当我需要执行任何操作时,我将通过
ref
。否则
ref
将被
nil
表示没有委托。@Mike它也为我工作。但是有一段时间它崩溃了,我无法找出原因。你添加了objective-c异常断点吗?OP没有在他的问题或评论中声明他是从后台线程调用的,而是收到了一个无法识别的选择器异常,在这种情况下,它与线程无关。