如何返回到Objective-C中的先前视图? [英] How to go back to previous view in Objective-C?

查看:51
本文介绍了如何返回到Objective-C中的先前视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是iOS编程初学者,想实现返回首页的功能.

I am a beginner in iOS programming and I want to implement the functionality of going back to home view.

我使用过这个代码:

-(IBAction)onclickhome:(id)sender
{

    [self.navigationController popViewControllerAnimated:YES];
}

我在主页按钮点击事件中使用了 navigationController 但它没有跳转到主屏幕.

I have used navigationController in home button click event but it is not jump to home screen.

您有任何适用于我的代码的建议和源代码吗?

Do you have any suggestion and source code which applies to my code?

推荐答案

我不确定我是否理解您的问题.

I'm not sure I understand your question.

你说的

我在主页按钮点击事件中使用了 navigationController 但它是不跳转到主屏幕

I have used navigationController in home button click event but it is not jump to home screen

?

如果你想弹出到根控制器,你可以使用popToRootViewControllerAnimated.

If you want to pop to the root controller you can use popToRootViewControllerAnimated.

[self.navigationController popToRootViewControllerAnimated:YES];

来自 UINavigationController

popToRootViewControllerAnimated:

Pops all the view controllers on the stack except the root view controller and updates the display.
- (NSArray *)popToRootViewControllerAnimated:(BOOL)animated

如果你已经设置了一个 UINavigationController 并且它的根控制器被称为 A,那么如果你从 A 导航到 B,然后从 B 导航到 C,你有两种可能回到以前的控制器(你可以有其他的,但我列出了主要的):

If you have set up a UINavigationController and its root controller is called A, then if you navigate from A to B and then from B to C you have two possibilities to come back to a previous controller (you can have others but I list the main ones):

  • 使用 popViewControllerAnimated
  • 从 C 导航回 B
  • 使用 popToRootViewControllerAnimated
  • 从 C 导航回 A
  • navigate back from C to B with popViewControllerAnimated
  • navigate back from C to A with popToRootViewControllerAnimated

这篇关于如何返回到Objective-C中的先前视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆