I am working on an iPhone's view which composed 3 elements, UITextView, UIToolBar with an UIBarButtonItem.
The goal is, I want UIBarButtonItem change its style from 'edit' (UIBarButtonSystemItemEdit) to 'Done' (UIBarButtonSystemItemDone) and update new selector to new method.
First of all, I have tried following code but it doesn't work:
Could you help me on this idea?
to change the button the Done button use this
to change the button to Edit button use this
I ended up doing something like this. Unfortunately, setting the title directly did not work, for some reason it was nil and would not let me set it to a different value. The self.editButton comes from an IBOutlet with the target and actions set. This code uses ARC. I hope this helps someone.
There is a builtin bar button with this behaviour, you get it via the
editButtonItem
property of a UIViewContoller. Tabbing that button will change the view controller it came from into editing mode, and toggle the button into a done button.If you have added the button through IB then make sure to set the identifier to Custom Also allocate a button in the .h with appropriate IBOutlet and Property Synthesize the button in .m
Then in your code do the following: