viewDidAppear实际上出现了吗?

时间:2011-06-14 09:20:15

标签: iphone objective-c viewdidappear

我知道这个问题与this听起来类似,但我已经知道了解决方法。这更像是一个分析问题。

以上链接是UITabBarController特有的问题,但我在UINavigationController时也观察到pushViewController:... animated:NO的行为,即。{没有动画。

所以我的问题是为什么视图出现在viewDidAppear方法之后,而它的名字暗示,并且定义说,该视图已经出现(定义说视图已添加到窗口中)。

我在方法中标记了一个断点来查看调用堆栈,这里是推送到UINavigationController的日志:

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

这是日志:

(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.

1 个答案:

答案 0 :(得分:-1)

我发现了以下内容:

  • ViewWillAppear:我通常只使用ViewWillAppear来更新表单上的数据。因此,对于上面的示例,我将使用它来实际将数据从我的域加载到表单中。创建UIViews是相当昂贵的,你应该尽可能避免在ViewWillAppear方法上这样做,因为当它被调用时,这意味着iPhone已经准备好向用户显示UIView,你在这里做的任何重量将以非常明显的方式影响性能(如动画延迟等)。

  • ViewDidAppear:最后,我使用ViewDidAppear来启动需要很长时间才能执行的新线程,比如执行webservice调用以获取上面表单的额外数据。好的方面是因为视图已经存在并且正在向用户显示,所以在获取数据时可以向用户显示一条漂亮的“等待”消息

从SO问题中被盗:What is the difference between -viewWillAppear: and -viewDidAppear:?