Uibarbuttonitem on button toggle or hide implementation case in iOS development

Source: Internet
Author: User

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

  1. -(void) Viewdidload {
  2. [Super Viewdidload];
  3. Selfself.navigationItem.rightBarButtonItem = Self.editbuttonitem;
  4. }
  5. -(void) setediting: (BOOL) editing animated: (bool) Animated {
  6. [Super Setediting:editing animated:animated];
  7. Don ' t show the back button while editing.
  8. [Self.navigationitem sethidesbackbutton:editing Animated:yes];
  9. if (editing) {
  10. Self.navigationItem.leftBarButtonItem = [[[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem: Uibarbuttonsystemitemadd
  11. Target:self Action: @selector (INSERTME)] autorelease];
  12. }else {
  13. Self.navigationItem.leftBarButtonItem = Nil;
  14. Self.navigationItem.leftBarButtonItem = [[[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem: Uibarbuttonsystemitemcancel
  15. Target:self Action: @selector (Backbutton)] autorelease];
  16. }
  17. }

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.