简体   繁体   中英

iOS back button behaviour : double back

I have 3 view controllers : A ->segue1-> B ->segue2-> C

When the user is on "C" and press the "back" button, I would like to go directly to A instead of B. How can I do that with swift ?

Thanks

If you are using navigation controller you can use popToRootViewControllerAnimated(_:) .

In case you have presented both controllers modally you can call dismissViewControllerAnimated(_:completion:) in your A controller.

Create your own back button :

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

And pop to root controller :

-(void)tapped:(UIButton*)sender {
   [self.navigationController popToRootViewControllerAnimated(NO)];
}

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