UIAlertView在iOS7上崩溃私有方法

时间:2014-02-19 10:41:25

标签: objective-c ios7 crash uialertview

堆栈如下,如何修复此崩溃? 它只在iOS7中,为什么堆栈中有uitableview?

0 libobjc.A.dylib objc_msgSend + 5
1 UIKit -[UIAlertView(Private) modalItem:shouldDismissForButtonAtIndex:] + 62
2 UIKit -[_UIModalItemsCoordinator _notifyDelegateModalItem:tappedButtonAtIndex:] + 94
3 UIKit -[_UIModalItemAlertContentView tableView:didSelectRowAtIndexPath:] + 894
4 UIKit -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1078
5 UIKit -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 214
6 UIKit _applyBlockToCFArrayCopiedToStack + 316
7 UIKit _afterCACommitHandler + 430
8 CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 20

- (id)initWithIdentifier:(LTAlertMsgIdentifier)alertIdentifier
                delegate:(id /*<UIAlertViewDelegate>*/)delegate
       cancelButtonTitle:(NSString *)cancelButtonTitle
       otherButtonTitles:(NSString *)otherButtonTitles, ... {

    LTAlertMsgManager *sharedAlertMsgMgr = [LTAlertMsgManager shareAlertManageInstance];

    NSString *strMsg = [sharedAlertMsgMgr getLTAlertMsgByAlertID:alertIdentifier];
    if ([NSString isBlankString:strMsg]){
        // alert is invalid, if alert message is empty
        return nil;
    }

    NSString *strTitle = [sharedAlertMsgMgr getLTAlertTitleByAlertID:alertIdentifier];
    if (self = [super initWithTitle:([NSString isBlankString:strTitle] ? nil : strTitle)
                            message:strMsg
                           delegate:delegate
                  cancelButtonTitle:cancelButtonTitle
                  otherButtonTitles:nil]){
        va_list args;
        va_start(args, otherButtonTitles);
        for (NSString *arg = otherButtonTitles; arg != nil; arg = va_arg(args, NSString*))
        {
            [self addButtonWithTitle:arg];
        }
        va_end(args);
    }

    NSLog(@"cancel button index - %d", self.cancelButtonIndex);
    return self;

}

2 个答案:

答案 0 :(得分:2)

UIAlertView中的按钮是使用UITableView实现的。这就是为什么点击按钮会触发tableView:didSelectRowAtIndexPath

导致此类错误的典型问题是:

  1. 警告未显示在主线程中
  2. 已取消分配代理(确保警报代表在警报的整个生命周期内保留在某处)。

答案 1 :(得分:0)

请参阅iOS 7 bug or my bug in UIAlertView

UIAlertView委托是 @property(nonatomic, assign) id delegate,因此请在取消分配代理时确保alertView.delegate = nil