The demand is: Click the Back button, automatically save the settings, and then return to the previous screen, the return button must use the kind with the left arrow, used to understand the iOS.
I started with iOS default Backbarbuttonitem, but found that it couldn't receive events, even though I set the target and the action didn't work at all. With Leftbarbuttonitem, it is possible to receive events, but the style cannot be the arrow that returns the button.
Distress, the last several attempts, the web also turned n times finally found a way:
No additional images are required, the code is as follows:
OBJC Code
- UIButton *backbutton = [UIButton buttonwithtype:101];
- [Backbutton addtarget:self Action: @selector (back) forcontrolevents:uicontroleventtouchupinside];
- [Backbutton Settitle:canceltext Forstate:uicontrolstatenormal];
- Uibarbuttonitem *backitem = [[[Uibarbuttonitem alloc] Initwithcustomview:backbutton] autorelease];
- Self.navigationItem.leftBarButtonItem = Backitem;
Let Navigationitem.leftbarbuttonitem have a backbarbuttonitem look style