我回来问过这个问题 . 但还没有解决方案,这是我的方案 .
//RootViewController.m
[self.navigationController pushViewController:view1 Animated:YES];
这是View1.m
UIBarButtonItem *back_of_view2 = [[UIBarButtonItem alloc]initWithTitle:@"Back to RootViewfromview2"
target:self
action:@selector(backClicked:)];
[self.navigationController pushViewController:view2 animated:YES];
这是backClicked方法:(仍在view1.m中)
-(void)backClicked:(UIBarButtonItem *)back_of_view2
{
[self.navigationController popToRootViewController Animated:YES]
}
我能够将view2中的后退按钮作为“返回RootViewfromview2”,但是没有调用backClicked操作,当我点击后面时,我得到了view1,这是默认操作 . 但是,当我在view2.m中设置leftBarButtonItem时
UIBarButtonItem *backtoOne = [[UIBarButtonItem alloc]initWithTitle:@"JumptorootView" style:UIBarButtonItemStyleBordered target:self action:@selector(someMethod:)];
-(void)someMethod:(UIBarButtonItem *)backtoOne
{
[self.navigationController popToRootViewController animated:YES];
}
现在..,如果我使用leftBarButtonItem ..,Everthing工作正常,但我不会得到后面的箭头..
2 回答
您可以像默认导航栏中显示的后退按钮一样使用图像 . 如果您覆盖导航栏上的后退按钮,就像在上面的代码中那样,那么您将无法获得默认的后退按钮,而是创建一个像后面的图像按钮并将该图像分配给左侧栏按钮项 .
希望能帮助到你.......
处理这种情况的最佳方法是
viewController2
通过委托协议发送viewController1
消息's about to be popped off the navigation stack. In this sample, I' m假设viewController2
是类DetailViewController
的实例 .