이 두개의 차이를 처음에는 잘 모르죠. 

아래 자세한 영문 설명이 있습니다. (윽 돌 날라온다 ...) 

한글로 설명을 하자면.... 

view는 한개의 object죠. 

viewDidLoad는 view object가 생성된 후 발생하는 이벤트입니다. 메모리에 view가 올라온 다음이라는 것입니다. 

그리고 viewWillAppear는 view가 안보이다가 다시 보이게 되었을때 발생하는 이벤트입니다. 

뷰가 A => B => C 이렇게 네비게이션이 발생할때 

처음에 A => B => C 갈때는 viewDidLoad와 viewWillAppear가 모두 발생합니다. 
C => B => A로 돌아올때는 viewWillAppear만 발생하는 것입니다. 
그다음에 A=>B=>C로 갈때도 viewWillAppear만 발생하는 것입니다. 

생성시점과 보여주는 시점을 분리한 것입니다. 



1) ViewDidLoad - Whenever I'm adding controls to a view that should appear together with the view, right away, I put it in the ViewDidLoad method. Basically this method is called whenever the view was loaded into memory. So for example, if my view is a form with 3 labels, I would add the labels here; the view will never exist without those forms. 

2) ViewWillAppear: I use ViewWillAppear usually just to update the data on the form. So, for the example above, I would use this to actually load the data from my domain into the form. Creation of UIViews is fairly expensive, and you should avoid as much as possible doing that on the ViewWillAppear method, becuase when this gets called, it means that the iPhone is already ready to show the UIView to the user, and anything heavy you do here will impact performance in a very visible manner (like animations being delayed, etc). 

3) ViewDidAppear: Finally, I use the ViewDidAppear to start off new threads to things that would take a long time to execute, like for example doing a webservice call to get extra data for the form above.The good thing is that because the view already exists and is being displayed to the user, you can show a nice "Waiting" message to the user while you get the data.


출처 : http://kapps.co.kr/bbs/board.php?bo_table=m52&wr_id=33

+ Recent posts