iphone

iPhone exception: index 0 beyond bounds for empty array


*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 0 beyond bounds for empty array'
*** Call stack at first throw:

In my TableViewController I am loading list of arrays..... with selected it displays its detailedViewController. When I get back and selected the same index or another index i get this exception NSRangeException.

What can I do to solve this?


Solution

  • The array is empty at that point. A good idea is, add some lines of code like this:

    NSLog(@"\n\n here, there are this many items: %d \n\n", [yourArrayName count]);
    

    put that line in everywhere possible, add it in at least ten places.

    Open your console ("Run" menu in XCode).

    You'll soon figure out what is going wrong! hope it helps.