简体   繁体   中英

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. 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];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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