The Uibarbuttonitem button toggle or hide case implementation case in IOS development is what this article is about, and the background of this code example is: There is an edit button on the right side of the navigation bar, and the Back button and the Add button on the left.
AD: "Offline activities" three Xin Rui HTML 5 Enterprise aggregation 51cto-Mobile front-end technology
iOS Development uibarbuttonitem button Toggle or hide case implementation case is the content of this article, the background of this code example is: There is an edit button on the right side of the navigation bar, the left side is the back button and the add button The code implementation of the button Toggle/Hide function is specifically: Click on the Edti button, the Back button is hidden, and the Add button is displayed.
When the user finishes editing, the Back button is displayed to hide the Add button. This feature is used in many applications, and the proper hiding of useless buttons is useful for keeping the interface simple and directing the user's actions.
Code
- -(void) Viewdidload {
- [Super Viewdidload];
- Selfself.navigationItem.rightBarButtonItem = Self.editbuttonitem;
- }
- -(void) setediting: (BOOL) editing animated: (bool) Animated {
- [Super Setediting:editing animated:animated];
- Don ' t show the back button while editing.
- [Self.navigationitem sethidesbackbutton:editing Animated:yes];
- if (editing) {
- Self.navigationItem.leftBarButtonItem = [[[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem: Uibarbuttonsystemitemadd
- Target:self Action: @selector (INSERTME)] autorelease];
- }else {
- Self.navigationItem.leftBarButtonItem = Nil;
- Self.navigationItem.leftBarButtonItem = [[[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem: Uibarbuttonsystemitemcancel
- Target:self Action: @selector (Backbutton)] autorelease];
- }
- }
Where the Back button is the system default, you can add other buttons by removing the comments from the else.
Uibarbuttonitem on button toggle or hide implementation case in iOS development