如何回到Objective-C中的上一个视图?

如何回到Objective-C中的上一个视图?,第1张

概述我是iOS编程的初学者,我想实现回到视图的功能. 我使用这段代码: -(IBAction)onclickhome:(id)sender{ [self.navigationController popViewControllerAnimated:YES];} 我在主页按钮点击事件中使用了navigationController,但它没有跳转到主屏幕. 您有任何适用于我的代码的建议和源 我是iOS编程的初学者,我想实现回到主视图的功能.

我使用这段代码:

-(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

如果要d出到根控制器,可以使用popToRootVIEwControllerAnimated.

[self.navigationController popToRootVIEwControllerAnimated:YES];

来自Apple的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,那么您有两种可能性来回到之前的控制器(您可以使用其他控制器但我列出了主控制器)那些):

>使用popVIEwControllerAnimated从C导航回B.>使用popToRootVIEwControllerAnimated从C导航回A

总结

以上是内存溢出为你收集整理的如何回到Objective-C中的上一个视图?全部内容,希望文章能够帮你解决如何回到Objective-C中的上一个视图?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1243242.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-06
下一篇2022-06-06

发表评论

登录后才能评论

评论列表(0条)

    保存