1

I know that this question sounds similar to this, but I am already aware of the work around. This is more of an analysis question.

The above link is a question specific to UITabBarController, but I also observed the behavior with UINavigationController, when I pushViewController:... animated:NO, ie. no animation.

So my question is WHY does view appears AFTER the viewDidAppear method, while its very name implies, and definition says, that view had already appeared (definition says view has beed added to the window).

I had marked a breakpoint in the method to see the call stack and here is the log for pushing to UINavigationController:

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidApear:animated];
    NSLog("...");              // <<<<<Breakpoint here
}

Here is the log:

(gdb) next
Single stepping until exit from function -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:], which has no line number information.
(gdb) next
Single stepping until exit from function -[UINavigationTransitionView _notifyDelegateTransitionDidStopWithContext:], which has no line number information.
(gdb) next
Single stepping until exit from function -[UINavigationTransitionView _navigationTransitionDidStop], which has no line number information.
(gdb) next
Single stepping until exit from function -[UIViewAnimationState sendDelegateAnimationDidStop:finished:], which has no line number information.
(gdb) next
Single stepping until exit from function +[UIViewAnimationState popAnimationState], which has no line number information.
(gdb) next
Single stepping until exit from function dyld_stub_objc_msgSend, which has no line number information.
(gdb) next
Single stepping until exit from function objc_msgSend, which has no line number information.
(gdb) next
Single stepping until exit from function -[NSObject(NSObject) release], which has no line number information.
(gdb) next
Single stepping until exit from function dyld_stub_objc_msgSend, which has no line number information.
(gdb) next
Single stepping until exit from function objc_msgSend, which has no line number information.
(gdb) next
Single stepping until exit from function -[UIViewAnimationState dealloc], which has no line number information.
(gdb) next
Single stepping until exit from function -[UINavigationTransitionView transition:fromView:toView:], which has no line number information.
(gdb) next
Single stepping until exit from function -[UINavigationTransitionView transition:toView:], which has no line number information.
(gdb) next
Single stepping until exit from function -[UINavigationController _startDeferredTransitionIfNeeded], which has no line number information.
(gdb) next
Single stepping until exit from function -[UILayoutContainerView layoutSubviews], which has no line number information.
(gdb) next
Single stepping until exit from function -[CALayer layoutSublayers], which has no line number information.
(gdb) next
Single stepping until exit from function dyld_stub_objc_msgSend, which has no line number information.
(gdb) next
Single stepping until exit from function objc_msgSend, which has no line number information.
(gdb) next
Single stepping until exit from function -[NSObject(NSObject) release], which has no line number information.
(gdb) next
Single stepping until exit from function CALayerLayoutIfNeeded, which has no line number information.
Community
  • 1
  • 1
Sailesh
  • 25,517
  • 4
  • 34
  • 47

1 Answers1

-1

I found the following:

  • 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).

  • 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

Stolen from the SO-question: What is the difference between -viewWillAppear: and -viewDidAppear:?

Community
  • 1
  • 1
Joetjah
  • 6,292
  • 8
  • 55
  • 90
  • 1
    Thanks for the reply Joetjah, but how is this relevant to my question? – Sailesh Jun 14 '11 at 09:56
  • The view gets shown right after viewDidAppear, but the stuff in there isn't loaded into the screen yet. According to the other posts, you could think of the viewDidAppear being a loader of actions defined in viewDidAppear, while the view is being outputted. In other words, things that don't have to be shown on appearing, but have to be calculated from start. Imagine for some reason, you decide to let the appearing of the view happen through an animation with a time of 3 seconds. That would have been 3 seconds of 'waste', but instead you can load stuff in meanwhile through viewDidAppear. – Joetjah Jun 14 '11 at 10:00