简体   繁体   English

如何使后退按钮始终转到上一个视图控制器

[英]How to have a back button always go to the previous view controller

I have multiple views, some of which are part of tabBarControllers, and the views are pushing to one view controller called View2 . 我有多个视图,其中一些是tabBarControllers的一部分,并且这些视图正在推送到一个名为View2视图控制器。 When I go back to the view that presented view2, how would I go back to a specific tab in the tab bar instead of going to the first one? 回到显示view2的视图时,如何回到标签栏中的特定标签,而不是第一个标签?

My action for the button that goes back to the first view is 我对返回到第一个视图的按钮的操作是

-(IBAction)goBackButton:(id)sender
{
    ViewController *firstView = [myStoryboard instantiateViewControllerWithIdentifier:@"view1"];
    [self presentViewController:firstView animated:YES completion:nil];
}

So ViewController is the class of the first view in the tab bar, and the tabBarController has the identifier "view1" 因此,ViewController是选项卡栏中第一个视图的类,并且tabBarController的标识符为“ view1”

If View2 has been pushed then your backbuttons action should call: 如果已按下 View2则您的后退按钮操作应调用:

[self.navigationController popViewControllerAnimated:YES];

If View2 is a modal then your backbuttons action should call: 如果View2模式的,则您的后退按钮操作应调用:

[self dismissViewControllerAnimated:YES completion:nil];

And whichever scene called View2 will reappear for you. 并且无论哪个场景称为View2都会重新出现。

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

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