I have asked this question sometime back. But havent got a solution yet,
Here is my scenario.
//RootViewController.m
[self.navigationController pushViewController:view1 Animated:YES];
Here is View1.m
UIBarButtonItem *back_of_view2 = [[UIBarButtonItem alloc]initWithTitle:@"Back to RootViewfromview2"
target:self
action:@selector(backClicked:)];
[self.navigationController pushViewController:view2 animated:YES];
And here is the backClicked method: (still in view1.m)
-(void)backClicked:(UIBarButtonItem *)back_of_view2
{
[self.navigationController popToRootViewController Animated:YES]
}
I am able to get the back button in view2 as “back to RootViewfromview2” but the action backClicked is not getting called and when I click on back, I am getting the view1 , which is the default action.
But, when I set the leftBarButtonItem in view2.m i.e
UIBarButtonItem *backtoOne = [[UIBarButtonItem alloc]initWithTitle:@"JumptorootView" style:UIBarButtonItemStyleBordered target:self action:@selector(someMethod:)];
-(void)someMethod:(UIBarButtonItem *)backtoOne
{
[self.navigationController popToRootViewController animated:YES];
}
Now.., if i use leftBarButtonItem..,Everthing works fine, but I wont get the back Arrow..
You can use the image like the back button shown in default navigation bar.If you override the back button on navigation bar , as you are doing in above code , then you will not get the default back button, instead create an image like a back button and assign that image to your left bar button item.
Hope it helps…….