简体   繁体   English

iOS后退按钮行为:双后退

[英]iOS back button behaviour : double back

I have 3 view controllers : A ->segue1-> B ->segue2-> C 我有3个视图控制器: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 ? 当用户在“ C”上并按“后退”按钮时,我想直接转到A而不是B。如何快速完成此操作?

Thanks 谢谢

If you are using navigation controller you can use popToRootViewControllerAnimated(_:) . 如果使用导航控制器,则可以使用popToRootViewControllerAnimated(_ :)

In case you have presented both controllers modally you can call dismissViewControllerAnimated(_:completion:) in your A controller. 如果您已经模态地显示了两个控制器,则可以在A控制器中调用dismissViewControllerAnimated(_:completion :)

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

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

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