Sponsors

 

Monday, July 27, 2009

Code Journal: Edit Mode on Table Views


I mentioned how my code worked for Edit mode on a table view in my iPhone app using the iPhone SDK 2.0 but then stopped working when I upgraded to 3.0. And I mentioned that after looking into things, it was amazing that my code worked at all the way I had it. Well, now I am going to explain the details.

It all has to do with the tableview methods beginUpdates and endUpdates. Based on the code that I originally used to base my code on, it appeared that beginUpdates was something you called when you entered the edit mode, and endUpdates was something you called when you exited edit mode. Nothing could be further from the truth!

Basically, these methods have something to do with animation of the cells on the table view. You want to do the beginUpdates, move into the table view's edit mode then call the endUpdates right away. Then you want to do the same thing when exit the table view's edit mode.

Below is a screen shot where I am checking the status of an Edit button on my view to toggle the edit mode on my table view:

You will notice how my beginUpdates and endUpdates lines are before and after each setEditing: animated: method.

Hope this helps

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.