I'm new to iPhone and Apple development and working on my first application. It simple with only a TableView and a "detail view" when an item in a table is selected.
What I want to do is change the background color of the cell in the TableView based on some action taken in my "detail view".
When the application initially loads I customize the colors in -cellForRowAtIndexPath:
method, but when user navigates back from my detail view that function is not called, so my table view doesn't have the colors updated. The only way to get that refreshed now is to exit the application and start it up again. (I persist their selection with NSUserDefaults.)
Obviously, I want the table view to be refreshed when they come back form the detail view, but I don't know how to get a reference to a cell and in which method to do that. I'm assuming it should go in -viewDidAppear
, since that is called everything the view is shown.
Use [tableView reloadData]
- that will make the tableview run though the rows and rebuild itself.
You should really do that in viewWillAppear:
.
Also, you can get the visible cells of the table view by using its visibleCells
method. Due to the way table views work, other cells do not exist at all -- scrolling will trigger the delegate method and create new cells (or dequeue existing ones if you use dequeue...
).
I would add that if it is in a editing view that then saves some modified information stored in your table you should have a delegate that detects when the data was actually saved then reload your tableview. viewWillAppear will be fired every time your view appears. What I think you are after is only after data has been changed you want to refresh the table.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With