2014-10-06 135 views
-1

我使用iPhone 4S的我的应用程序模拟器(iOS版7.0.3),我收到以下错误[_NSArrayM objectAtIndex:]:指数4294967295超出范围[0..1]

*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 4294967295 beyond bounds [0 .. 1]' 
*** First throw call stack: 
(
    0 CoreFoundation      0x003085e4 __exceptionPreprocess + 180 
    1 libobjc.A.dylib      0x027568b6 objc_exception_throw + 44 
    2 CoreFoundation      0x002a94e6 -[__NSArrayM objectAtIndex:] + 246 
    3 Requisitions      0x0015007a -[PasswordLoginController3 _adjustInputPos] + 61 
    4 Requisitions      0x0015042a -[PasswordLoginController3 keyboardWasShown:] + 312 
    5 Foundation       0x02428bf9 __57-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke + 40 
    6 CoreFoundation      0x00364524 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 20 
    7 CoreFoundation      0x002bc00b _CFXNotificationPost + 2859 
    8 Foundation       0x02362951 -[NSNotificationCenter postNotificationName:object:userInfo:] + 98 
    9 UIKit        0x009ffb1b -[UIInputViewTransition postNotificationsForTransitionEnd] + 1054 
    10 UIKit        0x009f6138 __53-[UIPeripheralHost(UIKitInternal) executeTransition:]_block_invoke1332 + 455 
    11 UIKit        0x006993c0 -[UINavigationControllerKeyboardAnimationStyle launchAnimation:afterStarted:completion:forHost:fromCurrentPosition:] + 501 
    12 UIKit        0x009f5a7c -[UIPeripheralHost(UIKitInternal) executeTransition:] + 1258 
    13 UIKit        0x009f7c0e -[UIPeripheralHost(UIKitInternal) setInputViews:animationStyle:] + 1029 
    14 UIKit        0x009f8019 -[UIPeripheralHost(UIKitInternal) setInputViews:animated:] + 72 
    15 UIKit        0x009f8063 -[UIPeripheralHost(UIKitInternal) setInputViews:] + 67 
    16 UIKit        0x009ef2fa -[UIPeripheralHost(UIKitInternal) _reloadInputViewsForResponder:] + 1453 
    17 UIKit        0x006c969a -[UIResponder(UIResponderInputViewAdditions) reloadInputViews] + 287 
    18 UIKit        0x006c8f8b -[UIResponder becomeFirstResponder] + 550 
    19 UIKit        0x005cc19b -[UIView(Hierarchy) becomeFirstResponder] + 114 
    20 UIKit        0x00c4ce43 -[UITextField becomeFirstResponder] + 51 
    21 UIKit        0x005cc1e8 -[UIView(Hierarchy) deferredBecomeFirstResponder] + 67 
    22 UIKit        0x005cc27c -[UIView(Hierarchy) _promoteSelfOrDescendantToFirstResponderIfNecessary] + 115 
    23 UIKit        0x005cc53e __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 224 
    24 UIKit        0x005cc388 -[UIView(Hierarchy) _postMovedFromSuperview:] + 260 
    25 UIKit        0x005d74c1 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1847 
    26 UIKit        0x005ca9b1 -[UIView(Hierarchy) addSubview:] + 56 
    27 UIKit        0x00563848 __53-[_UINavigationParallaxTransition animateTransition:]_block_invoke + 1927 
    28 UIKit        0x005d13ef +[UIView(Animation) performWithoutAnimation:] + 82 
    29 UIKit        0x00562c96 -[_UINavigationParallaxTransition animateTransition:] + 1155 
    30 UIKit        0x0069de4e -[UINavigationController _startCustomTransition:] + 3446 
    31 UIKit        0x006aa0c7 -[UINavigationController _startDeferredTransitionIfNeeded:] + 688 
    32 UIKit        0x006aacb9 -[UINavigationController __viewWillLayoutSubviews] + 57 
    33 UIKit        0x007e4181 -[UILayoutContainerView layoutSubviews] + 213 
    34 UIKit        0x005da267 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355 
    35 libobjc.A.dylib      0x0276881f -[NSObject performSelector:withObject:] + 70 
    36 QuartzCore       0x022182ea -[CALayer layoutSublayers] + 148 
    37 QuartzCore       0x0220c0d4 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380 
    38 QuartzCore       0x0220bf40 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26 
    39 QuartzCore       0x02173ae6 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294 
    40 QuartzCore       0x02174e71 _ZN2CA11Transaction6commitEv + 393 
    41 QuartzCore       0x02175544 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92 
    42 CoreFoundation      0x002d04ce __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30 
    43 CoreFoundation      0x002d041f __CFRunLoopDoObservers + 399 
    44 CoreFoundation      0x002ae344 __CFRunLoopRun + 1076 
    45 CoreFoundation      0x002adac3 CFRunLoopRunSpecific + 467 
    46 CoreFoundation      0x002ad8db CFRunLoopRunInMode + 123 
    47 GraphicsServices     0x03ce39e2 GSEventRunModal + 192 
    48 GraphicsServices     0x03ce3809 GSEventRun + 104 
    49 UIKit        0x0056fd3b UIApplicationMain + 1225 
    50 Requisitions      0x000a712c main + 92 
    51 libdyld.dylib      0x03036701 start + 1 
    52 ???         0x00000001 0x0 + 1 
) 
libc++abi.dylib: terminating with uncaught exception of type NSException 

我试过这个线程CRASH: *** -[__NSArrayM objectAtIndex:]: index 4294967295 beyond bounds [0 .. 9],并试图在某个断点进行调试,但无济于事。我无法弄清楚问题出在哪里。目标C不是我的专长,但仍然解决这个问题。

方法_adjustInputPos

-(void) _adjustInputPos 
{ 
    UITextField *currentField = [inputFields objectAtIndex:currentInputIndex]; 
    CGFloat currentInputHeight = currentField.frame.origin.y; 
    UIView* v = [self.formView viewWithTag:70]; 
    if(v!=nil) { 
     currentInputHeight += v.frame.origin.y; 
    } 
    UIScrollView* sv = (UIScrollView*)self.view; 

    CGFloat offset = 0; 
    if (sv.contentOffset.y>=(currentInputHeight)) { 
     offset = (sv.frame.size.height-kbHeight)/1.5; 
    } else if((self.view.frame.size.height-kbHeight-currentInputHeight)<currentField.frame.size.height) { 
     offset = (sv.frame.size.height-kbHeight)/1.5; 
    } else { 
     return; 
    } 

    if(sv.contentOffset.y==offset) { 
     return; 
    } 

    CGPoint scrollPoint = CGPointMake(0.0, offset); 
    [sv setContentOffset:scrollPoint animated:YES]; 
} 

方法keyBoardWasShown

- (void) keyboardWasShown:(NSNotification*)notf 
{ 
    if(isHidden) { 
     return; 
    } 

    NSDictionary *info = [notf userInfo]; 
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size; 

    kbHeight = kbSize.height; 
    BOOL islandscape = [[ClientAuthenticator getInstance].actionHandler isLandscape]; 
    if(!islandscape && [LSUtility isTablet]) {//ipad portrait,no need. 
     return; 
    } 

    if(islandscape) { 
     kbHeight = kbSize.width; 
    } 

    if (is30Style) { 
     [self _adjustInputPos]; 
    } else { 
     [self _adjustInputPos31]; 
    } 
    UIScrollView *sv = (UIScrollView*)self.view; 
    CGSize size = CGSizeMake(sv.frame.size.width, sv.frame.size.height+kbHeight/1.5); 
    [sv setContentSize:size]; 
} 

由于

+0

找到哪条线。我的猜测是,你正试图做'[anArray objectAtIndex:anIndex]'没有设置anIndex。 – Larme 2014-10-06 19:48:24

+0

这是UInt32 max,所以它可能是你正在调用索引-1的方法 – 2014-10-06 19:51:57

+0

这是一个简单的调试,不应该在这里需要一个问题。该指数显然超出了负数,因为超过20亿的东西是负数。行号已识别并位于您的模块中。去那里,找出为什么索引是错误的。 – 2014-10-06 19:56:59

回答

5

42949672950xFFFFFFFF在十六进制或-1作为unsigned int

签入[PasswordLoginController3 _adjustInputPos] - 它要求objectAtIndex的值为-1(这是超出界限)。

编辑因为你添加的代码

UITextField *currentField = [inputFields objectAtIndex:currentInputIndex] 

这看起来是错误来自于线。什么是currentInputIndex的类型,它在哪里初始化/修改?

+0

这适用于iOS8,但在iOS 7.03或iOS 7.1中引发异常,您是否知道可能的原因? – yogsma 2014-10-06 19:57:25

+0

没有代码,很难说 – Larme 2014-10-06 20:31:23

+0

这部分代码来自外部库,当我调试时,它不会显示任何代码,但机器代码。我如何附加一个源代码? – yogsma 2014-10-13 18:31:46