kururu623
kururu623

Reputation: 3

how to fix tableview crash due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0]'

I am trying to create a tableview follow an example code on a book.But it always crash. the debugger show me the info:

2012-08-03 02:51:09.854 TableView[652:c07] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
*** First throw call stack:
(0x1794022 0x1194cd6 0x1780d88 0xfdd1b7 0x3b24 0x2e62 0xb2c54 0xb33ce 0x9ecbd 0xad6f1 0x56d21 0x1795e42 0x2065679 0x206f579 0x1ff44f7 0x1ff63f6 0x2083160 0x16e84 0x17767 0x26183 0x26c38 0x1a634 0x167eef5 0x1768195 0x16ccff2 0x16cb8da 0x16cad84 0x16cac9b 0x16c65 0x18626 0x1eb2 0x1e25)
terminate called throwing an exception(lldb) 

I have no idea what it mean. Sorry for the long code again.... If necessary,I can send the whole code.

Someone online said the problem occur is due to the plist,http://p2p.wrox.com/271591-post2.html but I can't modify the plist in Xcode 4.4.Xcode shows a green pointer at this code

- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
    NSManagedObject *object = [self.fetchedResultsController objectAtIndexPath:indexPath];
    cell.textLabel.text = [[object valueForKey:@"timeStamp"] description];
}

Upvotes: 0

Views: 2076

Answers (2)

Martin R
Martin R

Reputation: 539715

Your table view data source methods (numberOfSectionsInTableView:, tableView:numberOfRowsInSection: and tableView:cellForRowAtIndexPath:) use self.years as data source.

On the other hand, you have a fetched results controller that calls insertRowsAtIndexPaths:... and deleteRowsAtIndexPaths:... when a new "Event" entity is added to or removed from your Core Data store.

So you are mixing two things here that do not fit together. The crash happens because you add table view rows, but the data source is not changed accordingly.

Upvotes: 2

Nosrettap
Nosrettap

Reputation: 11320

This means that you are trying to access the 1st element of an array that has 0 elements. My guess is the error is on one of the lines where you call objectAtIndex.

Remember, array indexing starts at 0!!!

Upvotes: 0

Related Questions