PDA

View Full Version : Updating UITableView With New Articles




newtoiphonesdk
Aug 31, 2012, 11:43 PM
I'm trying to get a blog app to refresh the articles, and add any new articles that may have been written since prior launch.

The TableView uses an array _allEntries of all the articles in the feed. I was told that when the user clicks the refresh button, i should clear the array, and after clearing it, run the original [self refresh] code to parse the rss and repopulate the table view. I am doing that with:

[_allEntries removeAllObjects];
[self refresh];
However, when I do that, it crashes with error:

*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 4 beyond bounds for empty array'



CodeBreaker
Sep 2, 2012, 08:59 AM
What does [self refresh] do?

The error you are getting is because you initially had an array with more than 4 articles. In your table view's delegate you returned the row count which was equal to the number of objects in your array. So the table asked for the 4th object in your array, and as you removed all objects from your array you got a range exception.

You should either reload the table or insert/delete specific rows and return a correct row count to your table whenever you add/remove objects to your array.