谁能解释一下 backBarButtonItem Action 是如何被覆盖的?
我曾经问过这个问题。但还没有找到解决办法 这是我的场景。
//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 中的后退按钮作为“back to 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..,一切正常,但我不会得到后箭头..
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..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用像默认导航栏中显示的后退按钮一样的图像。如果您覆盖导航栏上的后退按钮,就像您在上面的代码中所做的那样,那么您将不会获得默认的后退按钮,而是创建一个像后退一样的图像按钮并将该图像分配给左栏按钮项目。
希望有帮助......
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.......
处理这种情况的最佳方法是当
viewController2
即将从导航堆栈中弹出时,通过委托协议向viewController1
发送消息。在此示例中,我假设viewController2
是类DetailViewController
的实例。The best way to handle this situation is for the
viewController2
to sendviewController1
a message via a delegate protocol when it's about to be popped off the navigation stack. In this sample, I'm assumingviewController2
is an instance of classDetailViewController
.