0

I have a segue in an iPhone app that crashes if the initiating view controller was reached via a certain path. In those cases when I try to segue to the next screen I get:

*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 2 beyond bounds [0 .. 1]'

It's happening after prepareForSegue returns but before the destination view controller takes over. As far as I can tell it's in system code at the time. The call stack only shows main and UIApplicationMain. I'm stumped. Has anyone seen this before?

  • Are you using any arrays in your app? If so, are you sending objectAtIndex: message to them? If possible try to show your code.... – Naga Mallesh Maddali Jan 30 '14 at 17:36
  • Can you reproduce it in the sim or is it reported by your users? – Jay Jan 30 '14 at 17:37
  • 1
    Try creating an exception breakpoint. Maybe it will help see what's happening. – TotoroTotoro Jan 30 '14 at 17:39
  • Through copious use of breakpoints I'm strongly convinced this isn't a result of me calling objectAtIndex:. It looks like it's crashing on something system code is doing. – Kevin Kelly Jan 30 '14 at 17:40
  • Jay: This is code that hasn't shipped. I'm seeing it in development on a physical device. BlackRider: I hadn't thought of that. I'll try it out. – Kevin Kelly Jan 30 '14 at 17:41
  • 1
    In addition to adding an exception breakpoint, when you look at the stack trace of the crash, drag the slider all the way to the right to show the maximum about of detail in the call stack. – Duncan C Jan 30 '14 at 17:47
  • An exception breakpoint led me right to it. A misplaced break statement made code execution go off in a screwy direction and it was indeed caused by a call to objectAtIndex: that shouldn't have been happening. That's the first time I've ever seen Xcode not give a proper call stack for this case. It's always pointed right to the offending call until now. Thank you. – Kevin Kelly Jan 30 '14 at 17:53
  • Glad you resolved it. Get used to Xcode not showing the offending line. It happens a LOT. It got much worse in the transition from Xcode 3 to 4, and has never recovered. Exception breakpoints help, but don't solve the problem. You should post your solution as an answer and accept it so other readers know the problem is solved. – Duncan C Jan 30 '14 at 18:32

0 Answers0