UIAlertView 崩溃 iOS7 上的私有方法



堆栈如下,如何修复此崩溃?它只在 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;
}

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

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

  1. 主线程未显示警报
  2. 已解除分配的委托(确保警报委托在警报的整个生命周期内保留在某个位置)。

请参阅 iOS 7 错误或 UI 中的错误

UIAlertView delegate is @property(nonatomic, assign) id delegate ,因此请确保在解除分配委托时alertView.delegate = nil

最新更新