2011-06-14 57 views
1

我知道這個問題聽起來很像this,但我已經意識到了解決方法。這更多的是一個分析問題。viewDidAppear調用BEFORE它實際上出現了嗎?

上面的鏈接是UITabBarController的具體問題,但我也觀察到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 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

我發現下面的:

  • ViewWillAppear:我使用ViewWillAppear通常只是爲了更新表格上的數據。因此,對於上面的示例,我將使用它實際將我的域中的數據加載到表單中。創建UIViews相當昂貴,你應該儘可能地避免在ViewWillAppear方法上做這件事,因爲當它被調用時,這意味着iPhone已經準備好向用戶展示UIView,並且你在這裏做的任何事情都很重會以非常明顯的方式影響性能(如動畫被延遲等)。

  • ViewDidAppear:最後,我使用ViewDidAppear來開始處理需要很長時間才能執行的事情的新線程,例如執行web服務調用以獲取上述表單的額外數據。好處是,因爲視圖已經存在,並顯示給用戶,則可以顯示一個漂亮的「等待」的信息給用戶,而你得到的數據

被盜從SO-問題:What is the difference between -viewWillAppear: and -viewDidAppear:?

+1

感謝Joetjah的回覆,但這與我的問題有什麼關係? – Sailesh 2011-06-14 09:56:02

+0

視圖在viewDidAppear後顯示,但其中的內容尚未加載到屏幕中。根據其他帖子,您可以將viewDidAppear視爲viewDidAppear中定義的動作的加載器,而視圖正在輸出。換句話說,不必在出現時顯示,但必須從頭開始計算。想象一下,出於某種原因,您決定讓視圖的出現通過動畫進行,時間爲3秒。那會是3秒的'浪費',但相反,您可以通過viewDidAppear同時加載內容。 – Joetjah 2011-06-14 10:00:23

相關問題