UITabBarButtonItem did not change its title

Posted on by Nick. Posted in objective c.

Today I needed to implement the UITableView's edit / delete functionality inside my UITableViewController. That is fairly simple: 

1. in Interface Builder add a UITabBarButtonItem 
2. from the identifier list select "Edit"
3. Associate with the correct file owner
4. Pick selector and
5. In the selector implementation change the title from "Edit" to "Done" and the other way round depending on the tableView.editing property.
(6. the actual delete operation is not covered in this post)  
I assumed that after tapping the tab button the label would change to "Done". Sadly that did not happen. After a bit of debugging I found that the weird behaviour is caused by a set of _barButtonItemFlags. One of these flags is called "isSystemItem". Unfortunately this flag is set by the Interface Builder in step 2 above.
The solution:  
In step 2 above select Custom and the set the Bar Item Title below in the Interface Builder. 
In step 5 make sure you set the title back to "Edit" when coming out from the editing mode.
Even better solution (biased oppinion):
Avoid using IB to create you UIBarButtonItem! Instead just create the button programmatically using initWithTitle:style:target:action  
How do you create your Buttons?