objective-cipadios5xcode4.3

viewWillAppear getting called before viewDidDisappear of another controller gets finished


I have 2 view controllers say VC-1, VC-2. I have VC-2 displayed over VC-1 through navigation stack. VC-1 has textView and VC-2 has webView. Now I need to update the VC-1's content as soon as VC-2 is popped off. Hence I am using viewDidDisappear method of VC-2 to set the content and using that in viewWillAppear of VC-1 to update the textView (VC-1's content). But before viewDidDisappear finishes itself viewWillAppear of VC-1 gets executed and the content is not updated. I have checked this by NSLogging. viewDidDisappear has some file reading stuff so I guess that is causing the problem. How can I make the WillAppear(of VC-1) to get called after DidDisappear(VC-2) gets finished?


Solution

  • -viewWillAppear: is called before your view comes on screen at all. -viewDidDisappear: is called after your view is wholly gone from the screen. Therefore on any sort of animated transition, e.g. a navigation stack pop/push, the incoming VC's -viewWillAppear: will necessarily be called before the departing VC's -viewDidDisappear: is called. This is perfectly correct.

    You should probably take the work you're doing in -viewDidDisappear: and move that to -viewWillDisappear: instead.