如何弹出当前视图控制器并返回到先前的视图控制器?

时间:2022-09-11 16:48:02

I am trying to use a back button which it needs to pop the current view controller so that i can go back to previous controller. All the controllers are just view controllers.

我在尝试使用一个后退按钮它需要弹出当前视图控制器这样我就可以回到以前的控制器。所有的控制器都是视图控制器。

3 个解决方案

#1


14  

this will pop the top controller from navigation controller stack!

这将弹出顶部控制器从导航控制器堆栈!

 [self.navigationController popViewControllerAnimated:YES];

and if you are not aware of UINavigationController and its uses then follow this link

如果您不知道UINavigationController及其用途,请按此链接进行

http://www.idev101.com/code/User_Interface/UINavigationController/

http://www.idev101.com/code/User_Interface/UINavigationController/

#2


2  

You need to use a UINavigationController. This maintains a stack of your view controllers. You can modify your view stack by calling pushViewController:animated and popViewController:animated.

你需要使用UINavigationController。这将维护视图控制器的堆栈。你可以通过调用pushViewController:animated和popViewController:animated来修改你的视图堆栈。

Initialize your instance of UINavigationController with a rootViewController (your first view controller), and then present your UINavigationController in some way, then all you need is to play around with your UINavigationController instance.

使用rootViewController(您的第一个视图控制器)初始化UINavigationController实例,然后以某种方式显示UINavigationController,然后您所需要的就是使用UINavigationController实例。

#3


-1  

if you are pushing the view controller use:

如果你正在推动视图控制器使用:

      [self.navigationController popViewControllerAnimated:NO];

else if you are using a modal transition use:

如果你使用的是模态过渡使用:

      [self dismissViewControllerAnimated:YES completion:^{
          //Stuff after dismissing
        }];

#1


14  

this will pop the top controller from navigation controller stack!

这将弹出顶部控制器从导航控制器堆栈!

 [self.navigationController popViewControllerAnimated:YES];

and if you are not aware of UINavigationController and its uses then follow this link

如果您不知道UINavigationController及其用途,请按此链接进行

http://www.idev101.com/code/User_Interface/UINavigationController/

http://www.idev101.com/code/User_Interface/UINavigationController/

#2


2  

You need to use a UINavigationController. This maintains a stack of your view controllers. You can modify your view stack by calling pushViewController:animated and popViewController:animated.

你需要使用UINavigationController。这将维护视图控制器的堆栈。你可以通过调用pushViewController:animated和popViewController:animated来修改你的视图堆栈。

Initialize your instance of UINavigationController with a rootViewController (your first view controller), and then present your UINavigationController in some way, then all you need is to play around with your UINavigationController instance.

使用rootViewController(您的第一个视图控制器)初始化UINavigationController实例,然后以某种方式显示UINavigationController,然后您所需要的就是使用UINavigationController实例。

#3


-1  

if you are pushing the view controller use:

如果你正在推动视图控制器使用:

      [self.navigationController popViewControllerAnimated:NO];

else if you are using a modal transition use:

如果你使用的是模态过渡使用:

      [self dismissViewControllerAnimated:YES completion:^{
          //Stuff after dismissing
        }];