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