Return button with left Arrow added on Uinavigationbar

Source: Internet
Author: User
Add a return button similar to Navigationcontroller with the following effect:



One, Uinavigationcontroller Navigationbar is unable to add the left arrow of the return button

Search the web for a while but there really is a way to add success, but only if the Navigationbar is not navigationcontroller.

If it is a navigationbar that cannot be added successfully, it appears

Terminating app due to uncaught exception ' nsinternalinconsistencyexception ', Reason: ' Cannot call SetItems:animated:dir ectly on a Uinavigationbar managed by a controller. '

Such a mistake, meaning that "Apple is not allowed to directly to be controlled by a controller Navibar setitems operation", carefully check, there is really such a rule


"The navigation bar managed by the controller." Pushing, popping or setting navigation items on a managed navigation bar are not supported.

The meaning is clear: this navibar is managed by controller and does not support pushing, popping or setting the items operation.

See here, I also very have no language, so had to cut their own diagram, cut out the style of left arrow to add Leftbarbuttonitem.


Two, separate uinavigationbar add the left arrow back button

But still posted out, a separate navigationbar how to add the left arrow Back button code, this code must have seen a lot of it, haha, take pains to paste it again

 Uinavigationitem *navigationitem = [[Uinavigationitem alloc] initwithtitle:@ "];
    [Self.navibar Pushnavigationitem:navigationitem Animated:no];
 Self.naviBar.delegate = self;
                                                                    Create a right button uibarbuttonitem *rightbutton = [[Uibarbuttonitem alloc] initwithtitle:@ "right"
                                                                   Style:uibarbuttonitemstyledone Target:self Action: @selector (clickrightbut
ton)];
    [Navigationitem Setrightbarbuttonitem:rightbutton];
    [Navigationitem settitle:@ "my Page"];
    Uinavigationitem *item = [Self.naviBar.items objectatindex:0];
    [Self.navibar Pushnavigationitem:item Animated:yes];
    Uinavigationitem *back = [[Uinavigationitem alloc] initwithtitle:@ "back"];
    Nsarray *items = [[Nsarray alloc] initwithobjects:back,item,nil]; [Self.navibar Setitems:items Animated:no]; 


How to capture the event where the left arrow returns the button. You need to implement the method in the Uinavigationbardelegate agreement.

-(BOOL) Navigationbar: (Uinavigationbar *) Navigationbar Shouldpopitem: (Uinavigationitem *) Item
{
    // Add here the action code after clicking the Back button
    NSLog (@ "aaaaaaaaaaaaa");
    return FALSE;
}

Finally put out the operation of the effect diagram


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.