简体   繁体   中英

How to completely reload view?

I know in IOS you can set a view to be redrawn with this:

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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