Can I use viewWillAppear instead of viewDidLoad for most of my initialization and setup?

I'm not good at understanding between controllers, so I need to tweak and test a lot of NSUserDefaults, could this cause any problems?


source to share

2 answers

It depends on what you intend to do after the form starts-to-finish loading the submission.

You don't want to do too much in viewWillAppear

(Called when the view is ready to be shown) as this can impact performance; typically you want to do things like update a table or update text on a label, etc. The method viewDidLoad

is called after the view has loaded, and it is usually possible to add things like buttons, labels, etc., whatever you want displayed on the screen. If you have some tasks that can take a long time, it is better to do them viewDidAppear

as soon as the view is already loaded; it is good practice to execute these methods on a separate thread, or at least provide the user with some kind of activity indicator until the job is done.



Remember this viewDidLoad

is called once after the view has loaded. But it viewWillAppear

is called when your view becomes visible. With this information, you can decide to post.

look here for more information.



All Articles