NSRangeException on iOS 8
I upgraded XCode 5 to 6 to test my projects out on the iPhone 6 and 6 Plus and was getting cryptic crashes on startup:
'*** -[__NSArrayM objectAtIndex:]: index 4 beyond bounds [0 .. 3]' *** First throw call stack: ( 0 CoreFoundation 0x000000010569b3f5 __exceptionPreprocess + 165 1 libobjc.A.dylib 0x0000000104b20bb7 objc_exception_throw + 45 2 CoreFoundation 0x00000001055864d3 -[__NSArrayM objectAtIndex:] + 227 3 UIKit 0x00000001028164e1 _UIViewTopDownSubtreeTraversal + 193 4 UIKit 0x0000000102e43286 -[UIView(UIConstraintBasedLayout_EngineDelegate) _invalidateSystemLayoutSizeFittingSizeAtEngineDelegateLevel] + 128 5 Foundation 0x0000000103aa66df -[NSISEngine tryToAddConstraintWithMarker:expression:integralizationAdjustment:mutuallyExclusiveConstraints:] + 915 6 Foundation 0x0000000103c2f678 -[NSLayoutConstraint _addLoweredExpression:toEngine:integralizationAdjustment:lastLoweredConstantWasRounded:mutuallyExclusiveConstraints:] + 275 7 Foundation 0x0000000103a9ae3a -[NSLayoutConstraint _addToEngine:integralizationAdjustment:mutuallyExclusiveConstraints:] + 220 8 UIKit 0x0000000102e40495 __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke_2 + 474 9 Foundation 0x0000000103aa8a8e -[NSISEngine withBehaviors:performModifications:] + 155 10 UIKit 0x0000000102e4029b __57-[UIView(AdditionalLayoutSupport)
After a LOT of trial and error and trying various XIBs in various configurations, the issue occurred because I was mixing some XIBs with Auto Layout turned on, containing other UIViews (based on XIBs) with AutoLayout off.
Turning AutoLayout off for all of my XIBs solved the issue.
2 Solutions Collect From Internet About “NSRangeException on iOS 8”
Faced the same issue. Found that the problem is in button whose layer was used as mask for another button’s layer for some visual effect (
CALayer‘s mask property). Removing mask button from view hierarchy fixed the problem. I just moved it to view controller scene in storyboard.
Looks like using layer as a mask caused problem in
_UIViewTopDownSubtreeTraversal function used by autolayout. Maybe other layer manipulations for some view also can.
One solution I found is that you need to have at least 6 screens and then the app won’t crash.
Still trying to get it to work with less screens.
Turned off Auto Layout on my only XIB (LaunchScreen.xib) but that didn’t solve the problem.
- what is self? when should i use it?
- How to set UILabel only width and height and constraints programatically
- Turn off console logging for specific objects
- Correct and secure manner of storing in-app-purchases
- Add a method to Card that creates a full deck of cards, with one card of each combination of rank and suit
- Could not insert new outlet connection error
- Register for messages from collabd like XCSBuildService to receive Xcode Bots integration number
- Problems with SSL Pinning and AFNetworking 2.5.0 (NSURLErrorDomain error -1012.)
- Handle timeout with Alamofire
- iOS8 Auto layout programatically pin to relative layout margin
- Could somebody provide generic and working XCode project settings which lead to successful Mac App store submission?
- iOS lazy-loading of table images
- Swift-Application with Login and offlinemodus
- How does one use namespaces in iOS objective-c code?