Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When is viewDidLoad / viewDidAppear actually called? [duplicate]

I always thought that viewDidAppear was called whenever your view appeared on the screen, but I've been told that, for example, when you background an app (by pressing home button) and then bring it back up, viewDidAppear is not called (going to background "doesn't remove the current view from the view hierarchy"). So, what does it actually mean for a view to "appear"? Also, what does it mean for a view to "load", ie. when does it actually happen (for example, when the app is opened by touching the app icon, etc.)

like image 471
b_pcakes Avatar asked Apr 15 '16 07:04

b_pcakes


2 Answers

Is Heirarchy Of this:- Alwys Whenevr Your View Controller Runs It Go Like This

1st ViewDidLoad

2nd ViewAppear

3rd ViewDidAppear

4th ViewWillDisAppear

5th ViewDidDisAppear

Last 6th ViewDidUnload

You Can Understand This by This Simple Life Example :-

Suppose You Are In Cafe And

1st==> You Ordered Coffee Then Service Here Your Call Then They Fill Your Coffee On The Cup (Note Loading Or Filling All Contain Like Coffee on Cup Is Called ViewDidLoad )

2nd==>> And When Service Put Coffee On Your Table (Note Is Called ViewWillAppear Where Your Coffee just Like Your ViewController View )

3rd==>> And When You See Your Coffe (Note Is Called ViewDidAppear Where Your View Can See On Your Screen Just Like When Your See Your Coffee )

4th==>> After That When You Finished Your Macachino Coffee And is Empty (Note is Called ViewWillDisAppear Where Unloading or Proccess Of Empty is Stands For ViewWillDisAppear )

5th & 6th==>> And After That When Service Came And It's Pick Up Your Coffee Cup And Take Back From You When Is Did Disappear From Your Eyes (Note is Called ViewDidDisAppear When View or Your Screen Is Go Blank Just Like Your Cup ) And Finally All Proccesss Done Here....

And If You Again ordered Diff. Coffee Aur Same Coffee That All Step Called Again Same Like That, You Have Multiple ViewController And They Call Again Again A--B--A--B

Thx For Listing This Story Happy Coding

like image 64
Rahul Sharma Avatar answered Oct 15 '22 01:10

Rahul Sharma


viewDidLoad is called when all outlets are initialized from a Storyboard.

viewDidAppear calls when a View Controller is added to another view controller hierarchy. Usually after all animations is finished, but not necessary.

If you implement custom controller which will contain some child view controllers, you will call didMoveToParentViewController of the child controllers when they are added to the parent. So, whenever you call this method viewDidAppear of child VC's will be called automatically.

like image 26
kelin Avatar answered Oct 15 '22 02:10

kelin