在实际出现之前调用过viewDidAppear吗?

问题描述

| 我知道这个问题听起来与此类似,但是我已经知道解决方法。这更多是一个分析问题。 上面的链接是特定于
UITabBarController
的问题,但是当我I2ѭ时,我也观察到
UINavigationController
的行为。没有动画。 所以我的问题是,为什么视图在
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 -[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 CALayerLayoutIfNeeded,which has no line number information.
    

解决方法

        我发现以下内容: ViewWillAppear:我通常使用ViewWillAppear只是为了更新表单上的数据。因此,对于上面的示例,我将使用它来将域中的数据实际加载到表单中。创建UIView相当昂贵,您应该避免在ViewWillAppear方法上执行尽可能多的操作,因为调用该方法时,它意味着iPhone已经准备好向用户显示UIView,而您在此处所做的任何繁重的工作将以非常明显的方式影响性能(例如动画被延迟等)。 ViewDidAppear:最后,我使用ViewDidAppear为需要很长时间才能执行的事情启动新线程,例如进行webservice调用以获取上述表单的额外数据,这是因为视图已经存在并且正在向用户显示,您可以在获取数据的同时向用户显示一个很好的“正在等待”消息 从SO问题中窃取:-viewWillAppear:和-viewDidAppear:有什么区别?