如何完全重新加载视图以便viewDidLoad再次运行? [英] How can I completely reload a view so that viewDidLoad gets run again?

查看:342
本文介绍了如何完全重新加载视图以便viewDidLoad再次运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想重新加载我的视图,以便 viewDidLoad 重做其所有工作。我怎么能在Swift中做到这一点?

I would like to reload my view so that viewDidLoad redoes all of its work. How can I do that in Swift?

推荐答案

viewViewDidLoad viewWillAppear 视图控制器生命周期的一部分,在 UIViewController 实例化后由iOS自动调用在视图出现在屏幕上之前。你可以在视图控制器类的任何地方调用它们,但这并不是一个好习惯,我绝不会建议你这样做!

viewViewDidLoad and viewWillAppear are part of the view controller lifecycle and are called automatically by iOS after your UIViewController got instantiated and before the view appears on the screen. You can call them anywhere in your view controller class, but that's not at all good practice and I would never recommend you to do so!

如果你有你想要的代码要在视图控制器的生命周期内多次执行,请将它放在单独的方法中,并从 viewDidLoad 以及代码中您需要的其他部分调用它们。

If you have code that you want to be executed at multiple times during the lifetime of your view controller, put it into separate methods and call these from viewDidLoad and from the other parts in your code where you need them.

您可以在Apple的文档

You can read more about the view controller life cycle in Apple's documentation.

这篇关于如何完全重新加载视图以便viewDidLoad再次运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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