Set the title and action of Backbarbuttonitem in iOS

Source: Internet
Author: User

First, set the title

set in the previous controller that needs to display the return key :

   1:  "Logout", Style:UIBarButtonItemStyle.Plain, Target:nil, Action:nil)
Second, add the action when the return is performed:

You can try to fill in the event listener's handling at Target and action in the previous line of code, but it won't work.

Description of Backbarbuttonitem Discussion

When this navigation item is immediately below the top item on the stack, the navigation controller derives the back Butto N for the navigation bar from this navigation item. When the "is" is nil, the navigation item uses the value of the "the" to "create an" appropriate back button. If you want to specify a custom image or title for the Back button, you can assign a custom bar button item (with your Cus Tom Title or image) to the property instead. When configuring your Bar button item, does not assign a custom view to it; The navigation item ignores the custom views on the back bar button anyway.

Explains that Backbarbuttonitem can only customize the image and title, and cannot override the target or action, and the system ignores other related settings.

If you simply need to rewrite the action to do some other work, you need to customize a Leftbarbuttonitem because the system-defined Leftbarbuttonitem has a higher priority than Backbarbuttonitem, When Leftbarbuttonitem is present, the Backbarbuttonitem is automatically ignored and the purpose of rewriting the backbarbuttonitem is achieved.

Watch out.

Generally we take the item on the navigation controller to take this:

Navigationitem.backbaritem

If this means that the outermost layer of the two-level navigation bar is set to item, there is generally no such nesting.

NavigationController.navigationItem.backBarButtonItem

REF:

http://blog.csdn.net/dreamno23/article/details/21085783

Http://www.cnblogs.com/ihojin/p/change-backbarbuttonitem-text.html

Set the title and action of Backbarbuttonitem in iOS

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.