简体   繁体   English

导航栏后退按钮方法

[英]Navigation bar back button method

I want to navigate to the particular page in my application and i also dont want to create any custom back button for that.If I can override the method of the navigation bar back button so I can call the poptorootviewcontroller.so i can go to specific page. 我想导航到我的应用程序中的特定页面,我也不想为此创建任何自定义后退按钮。如果我可以覆盖导航栏后退按钮的方法,那么我可以调用poptorootviewcontroller.so我可以去具体页。 Anyone knows what is the method that is called by the navigation bar button and if we can use it? 任何人都知道导航栏按钮调用的方法是什么,如果我们可以使用它?

You can try this.. Write your logic in this native method. 你可以尝试这个..用这种原生方法写你的逻辑。

-(void) viewWillDisappear:(BOOL)animated {

    [super viewWillDisappear:YES];
    // Your Code
}

You will have to provide the name and the implementation for the button method As there is no standard method .. 您必须提供按钮方法的名称和实现,因为没有标准方法..

self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(backButtonPressed)] autorelease];

implementation .. 实施..

-(void) backButtonPressed {
 NSLog(@"Back button presses");

}

Try to use the below code: 尝试使用以下代码:

NSArray * viewController = self.navigationController.viewControllers;
if([viewController count] > 3)
{
    UIViewController * vc = [viewController objectAtIndex:0];
    [self.navigationController popToViewController:vc animated:YES];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM