Search code examples
iphoneobjective-ciosuitableviewreloaddata

Should I clear table view before using reloadData?


I want to put new values in a table view.

My tableView:cellForRowAtIndexPath: has the following

if (cell == nil) { // do something }

When I remove the if statement on top and use reloadData the app crashes. Do I need to clear the old values in the table before I use reloadData? If so how?
Thanks

Edit:

I'm sorry i didnt mean that i put reloadData inside tableView:cellForRowAtIndexPath:. i put it inside another method and removed if (cell == nil) { // do something } from inside tableView:cellForRowAtIndexPath:


Solution

  • You should read the TableView Programming Guide to familiarize yourself with the concepts. reloadData is a method that eventually calls tableView:cellForRowAtIndexPath:.