如何回到Objective-C中的上一个视图?
发布时间:2020-12-16 04:55:47 所属栏目:百科 来源:网络整理
导读:我是iOS编程的初学者,我想实现回到主视图的功能. 我使用这段代码: -(IBAction)onclickhome:(id)sender{ [self.navigationController popViewControllerAnimated:YES];} 我在主页按钮点击事件中使用了navigationController,但它没有跳转到主屏幕. 您有任何适
我是iOS编程的初学者,我想实现回到主视图的功能.
我使用这段代码: -(IBAction)onclickhome:(id)sender { [self.navigationController popViewControllerAnimated:YES]; } 我在主页按钮点击事件中使用了navigationController,但它没有跳转到主屏幕. 您有任何适用于我的代码的建议和源代码吗? 解决方法
我不确定我理解你的问题.
你是什??么意思
? 如果要弹出到根控制器,可以使用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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |