2014-08-27 61 views
-1

我得到这个下面的例外,同时提示用户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_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]; 
} 
+1

予实现的相同代码并能正常工作。您是否为objective-c异常设置了断点? – Mike 2014-08-27 22:04:39

+0

警报解除后是否存在'ref'? – rebello95 2014-08-27 22:11:01

+0

其实我会在需要执行任何操作时传递'ref'。否则'ref'将是'nil'意味着没有委托。 – 2014-08-27 22:18:47

回答

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

为什么downvote? – 2014-08-27 23:41:17

+1

OP没有在他的问题或在他的意见中说他从后台线程调用,而是他收到一个无法识别的选择器异常,在这种情况下,它独立于线程。 – Milo 2014-08-27 23:57:19