[英]What happens when back button is pressed in navigationBar
I wonder what is the function is called when the back button is pressed on the navigationBar. 我不知道在导航栏上按下后退按钮时会调用什么函数。
I want to add some functionality when the button is pressed, who knows it? 我想在按下按钮时添加一些功能,谁知道呢?
Thanks in advance 提前致谢
The functionality you want is in the UINavigationBarDelegate
protocol. 所需的功能在UINavigationBarDelegate
协议中。 Implement the -navigationBar:shouldPopItem:
method and set your class as the delegate
of the navigation bar in question. 实现-navigationBar:shouldPopItem:
方法,并将您的类设置为相关导航栏的delegate
。
Assuming you're referring to native controls, there's no way to do quite what you want, just using the built-in stuff. 假设您指的是本机控件,则仅使用内置的东西就无法做您想要的任何事情。 What you want to do is create a 'fake' back button, and stick it up in the left side of the navigation bar. 您要做的是创建一个“假”后退按钮,并将其粘贴在导航栏的左侧。 Then you can set its target and action to whatever you like. 然后,您可以将其目标和操作设置为所需的任何值。
I suppose you're talking about the back button that automatically is added to a UINavigationBar when you push a new viewcontroller on a navigationcontroller. 我想您正在谈论的是当您在导航控制器上按下新的视图控制器时自动添加到UINavigationBar的后退按钮。
The default action for the back button is to pop the current viewcontroller from the navigation stack and return to the previous viewcontroller. 后退按钮的默认操作是从导航堆栈中弹出当前的ViewController,然后返回到先前的ViewController。 If you want to define a custom behaviour to the backbutton you'll have to create a new button and tie a selector to it's action property: 如果要为后退按钮定义自定义行为,则必须创建一个新按钮并将选择器绑定到其action属性:
//Create a new barbutton with an action
UIBarButtonItem *barbutton = [[UIBarButtonItem alloc] initWithTitle:@"Back"
style:UIBarButtonItemStyleDone target:self action:@selector(doSomething)];
// and put the button in the nav bar
self.navigationItem.leftBarButtonItem = barbutton;
[barbutton release];
Edit: 编辑:
//An example on how the doSomething method could be implemented. //有关如何实现doSomething方法的示例。
-(void) doSomething
{
//Do your custom behaviour here..
//Go back to the previous viewcontroller
[self.navigationController popViewControllerAnimated:YES];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.