繁体   English   中英

UIAlertView显示崩溃

[英]UIAlertView show crash

首次初始化时,我使UIAleartView显示信息:

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@""
                                                    message:@"..."
                                                   delegate:self
                                          cancelButtonTitle:@"..."
                                          otherButtonTitles:@"...", nil];
alertView.tag = 1;
[alertView show];

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    switch (alertView.tag) {
        case 1: {
            [UICKeyChainStore setString:@"YES" forKey:kDebutFirstMsgShow];
            if (buttonIndex == 0) {
                NSNotificationCenter *noti = [NSNotificationCenter defaultCenter];
                [noti postNotificationName:@"...." object:nil];
            }
            break;
        }

        default:
            break;
    }
}

这是日志:

2017-02-10 01:16:44.206 audition[1740:55532] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010b09bd4b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x000000010aad421e objc_exception_throw + 48
    2   CoreFoundation                      0x000000010afcd2eb -[__NSArrayM objectAtIndex:] + 203
    3   UIKit                               0x0000000109854e8f __86-[_UIAlertControllerView _unlocalizedOrderedPresentableAlertActionViewRepresentations]_block_invoke + 68
    4   CoreFoundation                      0x000000010b02b0b2 __53-[__NSArrayM enumerateObjectsWithOptions:usingBlock:]_block_invoke + 114
    5   CoreFoundation                      0x000000010b02af42 -[__NSArrayM enumerateObjectsWithOptions:usingBlock:] + 194
    6   UIKit                               0x0000000109854dfc -[_UIAlertControllerView _unlocalizedOrderedPresentableAlertActionViewRepresentations] + 213
    7   UIKit                               0x00000001098543b5 -[_UIAlertControllerView _reloadInterfaceActionViewRepresentations] + 50
    8   UIKit                               0x0000000109855f6e -[_UIAlertControllerView _setVisualStyle:] + 380
    9   UIKit                               0x00000001090bab35 -[UIAlertController _updateProvidedStyleWithTraitCollection:] + 455
    10  UIKit                               0x00000001090bac0f -[UIAlertController _updateProvidedStyle] + 57
    11  UIKit                               0x00000001090bae7a -[UIAlertController traitCollectionDidChange:] + 236
    12  UIKit                               0x0000000108eedfac -[UIViewController _traitCollectionDidChange:] + 108
    13  UIKit                               0x0000000108eee0cf -[UIViewController _updateTraitsIfNecessary] + 269
    14  UIKit                               0x0000000108e12957 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 884
    15  QuartzCore                          0x000000010bb2abf8 -[CALayer layoutSublayers] + 146
    16  QuartzCore                          0x000000010bb1e440 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
    17  UIKit                               0x0000000108e00928 -[UIView(Hierarchy) layoutBelowIfNeeded] + 1509
    18  UIKit                               0x0000000108df6e33 -[UIView(Geometry) setBounds:] + 2387
    19  UIKit                               0x0000000108df603d -[UIView(Geometry) _applyISEngineLayoutValuesToBoundsOnly:] + 608
    20  UIKit                               0x0000000108e0080e -[UIView(Hierarchy) layoutBelowIfNeeded] + 1227
    21  UIKit                               0x0000000108df315b -[UIView(Geometry) setFrame:] + 1297
    22  UIKit                               0x00000001090b9f26 -[UIAlertController loadView] + 201
    23  UIKit                               0x0000000108eef61c -[UIViewController loadViewIfRequired] + 201
    24  UIKit                               0x0000000108eefe70 -[UIViewController view] + 27
    25  UIKit                               0x0000000108f0a0a5 -[UIViewController _setPresentationController:] + 100
    26  UIKit                               0x0000000108f015f4 -[UIViewController _presentViewController:modalSourceViewController:presentationController:animationController:interactionController:completion:] + 1355
    27  UIKit                               0x0000000108f0328e -[UIViewController _presentViewController:withAnimationController:completion:] + 4971
    28  UIKit                               0x0000000108f0626b -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 530
    29  UIKit                               0x0000000108f05d51 -[UIViewController presentViewController:animated:completion:] + 179
    30  UIKit                               0x00000001098413bf -[_UIAlertControllerShimPresenterWindow presentAlertController:animated:completionBlock:] + 642
    31  UIKit                               0x000000010983f6f6 -[_UIAlertControllerShimPresenter _presentAlertControllerAnimated:completion:] + 219
    32  UIKit                               0x00000001090d42e6 -[UIAlertView _showAnimated:] + 278
    33  audition                            0x00000001063f9840 -[DebutVC viewWillAppear:] + 448
    34  UIKit                               0x0000000108ef596f -[UIViewController _setViewAppearState:isAnimating:] + 692
    35  UIKit                               0x0000000108ef607f -[UIViewController __viewWillAppear:] + 147
    36  UIKit                               0x0000000108e0b59b __86+[UIView(Internal) _transitionFromView:toView:duration:options:animations:completion:]_block_invoke + 62
    37  UIKit                               0x0000000108e085c0 +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] + 581
    38  UIKit                               0x0000000108e087f2 +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:animations:start:completion:] + 145
    39  UIKit                               0x0000000108e0b4bf +[UIView(Internal) _transitionFromView:toView:duration:options:animations:completion:] + 603
    40  UIKit                               0x0000000108f1677a -[UIViewController(UIContainerViewControllerProtectedMethods) transitionFromViewController:toViewController:duration:options:animations:completion:] + 771
    41  audition                            0x000000010645c1b1 -[MHTabBarController setSelectedIndex:animated:] + 2849
    42  audition                            0x000000010645cca3 -[MHTabBarController tabButtonPressed:] + 99
    43  UIKit                               0x0000000108d4f8bc -[UIApplication sendAction:to:from:forEvent:] + 83
    44  UIKit                               0x0000000108ed5c38 -[UIControl sendAction:to:forEvent:] + 67
    45  UIKit                               0x0000000108ed5f51 -[UIControl _sendActionsForEvents:withEvent:] + 444
    46  UIKit                               0x0000000108ed4910 -[UIControl touchesBegan:withEvent:] + 304
    47  UIKit                               0x0000000108dbd285 -[UIWindow _sendTouchesForEvent:] + 2043
    48  UIKit                               0x0000000108dbec33 -[UIWindow sendEvent:] + 4011
    49  UIKit                               0x0000000108d6b9ab -[UIApplication sendEvent:] + 371
    50  UIKit                               0x000000010955872d __dispatchPreprocessedEventFromEventQueue + 3248
    51  UIKit                               0x0000000109551463 __handleEventQueue + 4879
    52  CoreFoundation                      0x000000010b040761 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    53  CoreFoundation                      0x000000010b02598c __CFRunLoopDoSources0 + 556
    54  CoreFoundation                      0x000000010b024e76 __CFRunLoopRun + 918
    55  CoreFoundation                      0x000000010b024884 CFRunLoopRunSpecific + 420
    56  GraphicsServices                    0x000000010ca64a6f GSEventRunModal + 161
    57  UIKit                               0x0000000108d4dc68 UIApplicationMain + 159
    58  audition                            0x0000000106493c91 main + 241
    59  libdyld.dylib                       0x000000010d05868d start + 1

从日志文件NSRangeException中,有一个空数组,但我可以访问它的元素0。 但是当我评论[alertview show]时,Crash消失了; 崩溃的原因是什么?

崩溃日志显示您的代码在这里发生:

33  audition 0x00000001063f9840 -[DebutVC viewWillAppear:] + 448

不能show从警报viewWillAppear ,因为你的观点是不是在界面,但(它出现,但它没有这样做)。 尝试将show代码移至viewDidAppear

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM