1

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

上面的链接是一个特定于 的问题UITabBarController,但我也观察了UINavigationController, 当 I 时的行为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.
4

1 回答 1

-1

我发现了以下内容:

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

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

从 SO 问题中被盗:-viewWillAppear: 和 -viewDidAppear: 有什么区别?

于 2011-06-14T09:45:22.557 回答