Case study of Button switching or hiding on UIBarButtonItem in IOS development

Source: Internet
Author: User

IOS developmentOn UIBarButtonItemButtonThe example of switching or hiding a case is described in this article. The background of this code example is: the navigation bar has an edit button on the right, and the back button and add button on the left. Code ImplementationButtonThe switch/hide function is specific: Click edti button, the back button is hidden, and the add button is displayed.

After the user completes editing, the back button is displayed to hide the add button. This function is used in many applications, and it is useless to hide it properly.ButtonIt makes sense to keep the interface concise and guide user operations.

Code

 
 
  1. - (void)viewDidLoad {  
  2. [super viewDidLoad];  
  3. selfself.navigationItem.rightBarButtonItem = self.editButtonItem;  
  4. }  
  5. - (void)setEditing:(BOOL)editing animated:(BOOL)animated {  
  6.  
  7.     [super setEditing:editing animated:animated];  
  8.  
  9. // Don't show the Back button while editing.  
  10. [self.navigationItem setHidesBackButton:editing animated:YES];  
  11.  
  12. if (editing) {  
  13. self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd 
  14. target:self action:@selector(insertMe)] autorelease];  
  15. }else {  
  16. self.navigationItem.leftBarButtonItem = nil;  
  17. //self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel 
  18. target:self action:@selector(backButton) ] autorelease];  
  19. }  
  20.  

Among them, the back button is the system default. You can add otherButton.

Summary:IOS developmentOn UIBarButtonItemButtonAfter you have finished the introduction of switching or hiding cases, I hope this article will help you!

Related Article

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.