简体   繁体   English

如何完全重载视图?

[英]How to completely reload view?

I know in IOS you can set a view to be redrawn with this: 我知道在IOS中,您可以使用以下方法设置要重绘的视图:

self.view.setNeedsDisplay()

However, is there anyway to refresh the view in such a way that it recalls viewDidLoad() and all its constructor methods again? 但是,是否有某种方式刷新视图,使其再次调用viewDidLoad()及其所有构造函数方法?

What you can do is something like this: 您可以执行以下操作:

var window: UIWindow?

let storyBoard : UIStoryboard = UIStoryboard(name: "StoryBoardName", bundle:nil)

let viewController = storyBoard.instantiateViewControllerWithIdentifier("ExampleIdentifier") as! ExampleViewController

And then inside whatever function: 然后在任何函数中:

window!.rootViewController = viewController
window!.makeKeyWindow()

This will basically reload/redraw the window. 基本上,这将重新加载/重绘窗口。 You should not try to directly call viewDidLoad() 您不应该尝试直接调用viewDidLoad()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM