1

この質問はこれと似ているように聞こえますが、回避策については既に認識しています。これはより分析的な質問です。

上記のリンクは に固有の質問ですが、でUITabBarControllerの動作も観察しました。アニメーションなし。UINavigationControllerpushViewController:... 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 を使用します。したがって、上記の例では、これを使用して実際にドメインからフォームにデータをロードします。UIView の作成にはかなりのコストがかかります。ViewWillAppear メソッドでそれを行うことはできるだけ避ける必要があります。これが呼び出されると、iPhone がすでに UIView をユーザーに表示する準備ができていることを意味するためです。非常に目に見える形でパフォーマンスに影響を与えます (アニメーションの遅延など)。

  • ViewDidAppear: 最後に、ViewDidAppear を使用して、実行に時間がかかる処理への新しいスレッドを開始します。たとえば、上記のフォームの追加データを取得するために Web サービス呼び出しを行うなどです。良いことは、ビューが既に存在するためです。ユーザーに表示されている場合、データを取得している間、ユーザーに素敵な「待機中」メッセージを表示できます

SO-質問から盗まれた: -viewWillAppear: と -viewDidAppear: の違いは何ですか?

于 2011-06-14T09:45:22.557 に答える