views:

37

answers:

1

I have a table view with a search bar at the top of the page. When I scroll through the table and then press in the search bar, while the table is still scrolling I get a

* Terminating app due to uncaught exception 'NSRangeException', reason: '* -[NSCFArray objectAtIndex:]: index (37) beyond bounds (0)'

I'm a little lost on what the issue here is. I'm thinking that the delegate methods for the table view don't get completely executed before it calls the search bar delegate methods.

Any help would be greatly appreciated.

Thank you.

+3  A: 

Are you using threads?

Both the search bar and the table view delegate methods should be on the main thread and, thus, there is no way for one to interrupt the other.

However, events can be handled during scroll. If your search is clearing the table view during scroll, that may be an issue.

bbum
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar { sBar.showsCancelButton = YES; // only show the status bar’s cancel button while in edit mode sBar.autocorrectionType = UITextAutocorrectionTypeNo; [self.tableData removeAllObjects]; // flush the previous search content}your right I'm clearing the table view when the search bar is pressed. I commented out the line where I'm clearing the table and it resolved the issue. Thank you so much for pointing that out to me.
Toret
don't forget to accept the answer toret
Joshua Weinberg
Thanks :) I tried but it told me I had to wait for 2 mins. I checked it off now thank you
Toret
I would also encourage you to file a bug on that behavior; unless you are customizing the table view heavily, then it should be robust against the data being removed (assuming everything is happening in the main thread).
bbum