How do I add a button to Uinavigationbar?

Source: Internet
Author: User

Mads Mob?k: Example code to add a button to Uinavigationbar

12345678 UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"Done"    style:UIBarButtonItemStyleDone target:nil action:nil];UINavigationItem *item = [[UINavigationItem alloc] initWithTitle:@"Title"];item.rightBarButtonItem = rightButton;item.hidesBackButton = YES;[bar pushNavigationItem:item animated:NO];[rightButton release];[item release];

But usually you have to have a navigation Controller that allows you to write the following code:

1234 UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"Done"    style:UIBarButtonItemStyleDone target:nil action:nil];self.navigationItem.rightBarButtonItem = rightButton;[rightButton release];

Amagrammer: The answer upstairs is very good, and I would like to make some suggestions:

If you modify the title of the Back button, you must modify it in the previous view controller instead of where it will be displayed. It's like saying, "Hey, if you've ever placed another view controller on this, then call the Back button instead of default."

If you want to hide the back button in a particular state, such as when displaying uipickerview, use Self.navigationItem.hidesBackButton = YES; When you exit this state, remember to set it back.

If you want to display a special symbolic button, use the InitWithBarButtonSystemItem:target:action method with controls like Uibarbuttonsystemitemadd.

Remember, the meaning of the symbol is up to you, but be careful with the HMI interaction Guide. Using uibarbuttonsystemitemadd means deleting an item will likely cause your app to be rejected.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

How do I add a button to Uinavigationbar?

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.