__NSArrayM索引超出范围

时间:2016-03-16 12:12:05

标签: ios arrays indexing crash sigabrt

很抱歉发布了类似的问题。

我在Objective C中继承了一个iOS应用程序,需要修改它。最初它在旧版Xcode中运行良好。然后我更新了我的Xcode,然后在以下方法中遇到了一个未捕获的数组索引超出范围的异常。

int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([MartialArtsAppDelegate class]));
    }
}

转储堆栈在CoreFoundation框架中深入说明, 超出边界[0..1]的NSMutableArray有一个索引3。 我不确定这是什么意思。我看不出它是哪个阵列。

此外,我没有看到我在应用程序中声明了NSMutableArray的位置。 转储堆栈如下。非常感谢您的协助。

2016-03-16 19:54:56.522 HanDynastyMartialArts[480:5616] WARNING: A Gesture recognizer (<UISwipeGestureRecognizer: 0x7ff9fa596790; state = Possible; view = <UIView 0x7ff9fa599c10>; target= <(action=upSwipeGesture:, target=<MartialArtsViewController 0x7ff9fb04ea00>)>; direction = up>) was setup in a storyboard/xib to be added to more than one view (-><UIView: 0x7ff9fa5af170; frame = (0 0; 320 450); autoresize = RM+BM; gestureRecognizers = <NSArray: 0x7ff9fa5d77b0>; layer = <CALayer: 0x7ff9fa5af2d0>>) at a time, this was never allowed, and is now enforced. Beginning with iOS 9.0 it will be put in the first view it is loaded into.

2016-03-16 19:54:56.587 HanDynastyMartialArts[480:5616] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM insertObject:atIndex:]: index 3 beyond bounds [0 .. 1]'
*** First throw call stack:

    (

    0   CoreFoundation                      0x0000000106658f65 __exceptionPreprocess + 165

    1   libobjc.A.dylib                     0x00000001060d2deb objc_exception_throw + 48

    2   CoreFoundation                      0x000000010651ff55 -[__NSArrayM insertObject:atIndex:] + 901

    3   Foundation                          0x0000000105b11a11 -[NSKeyValueSlowMutableArray insertObject:atIndex:] + 106

    4   CoreFoundation                      0x0000000106574432 -[NSMutableArray insertObjects:count:atIndex:] + 162

    5   CoreFoundation                      0x000000010657419f -[NSMutableArray insertObjectsFromArray:range:atIndex:] + 335

    6   CoreFoundation                      0x0000000106574023 -[NSMutableArray addObjectsFromArray:] + 723

    7   UIKit                               0x0000000104c2e49f -[UIRuntimeOutletCollectionConnection performConnect] + 860

    8   CoreFoundation                      0x0000000106599b10 -[NSArray makeObjectsPerformSelector:] + 224

    9   UIKit                               0x0000000104967306 -[UINib instantiateWithOwner:options:] + 1864

    10  UIKit                               0x000000010475284d -[UIViewController _loadViewFromNibNamed:bundle:] + 381

    11  UIKit                               0x0000000104753179 -[UIViewController loadView] + 178

    12  UIKit                               0x000000010475347c -[UIViewController loadViewIfRequired] + 139

    13  UIKit                               0x0000000104796c26 -[UINavigationController _layoutViewController:] + 54

    14  UIKit                               0x00000001047974dd -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 433

    15  UIKit                               0x0000000104797633 -[UINavigationController _startTransition:fromViewController:toViewController:] + 116

    16  UIKit                               0x0000000104798879 -[UINavigationController _startDeferredTransitionIfNeeded:] + 890

    17  UIKit                               0x000000010479967d -[UINavigationController __viewWillLayoutSubviews] + 57

    18  UIKit                               0x000000010493163d -[UILayoutContainerView layoutSubviews] + 248

    19  UIKit                               0x000000010467911c -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 710

    20  QuartzCore                          0x000000010a55536a -[CALayer layoutSublayers] + 146

    21  QuartzCore                          0x000000010a549bd0 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366

    22  QuartzCore                          0x000000010a549a4e _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24

    23  QuartzCore                          0x000000010a53e1d5 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277

    24  QuartzCore                          0x000000010a56b9f0 _ZN2CA11Transaction6commitEv + 508

    25  QuartzCore                          0x000000010a56c154 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92

    26  CoreFoundation                      0x00000001065849d7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23

    27  CoreFoundation                      0x0000000106584947 __CFRunLoopDoObservers + 391

    28  CoreFoundation                      0x0000000106579ebc CFRunLoopRunSpecific + 524

    29  UIKit                               0x00000001045c398d -[UIApplication _run] + 402

    30  UIKit                               0x00000001045c8676 UIApplicationMain + 171

    31  HanDynastyMartialArts               0x00000001042b3cbf main + 111

    32  libdyld.dylib                       0x0000000106fae92d start + 1

    33  ???                                 0x0000000000000001 0x0 + 1

    )
    libc++abi.dylib: terminating with uncaught exception of type NSException
    (lldb) 

1 个答案:

答案 0 :(得分:1)

要查看导致错误的实际语句,请添加异常断点:

  1. 从主菜单调试:断点:创建异常断点。
  2. 右键单击断点并将异常设置为Objective-C。
  3. 添加动作:“po $ arg1”。
  4. 运行应用程序以获取断点,您将位于导致异常的行,并且错误消息将位于调试器控制台中。

    Breakpoint example: