2013-04-09 88 views
0

當我讀的UINavigationController,物業navigationItem的API文檔,具有尖端的navigationItem屬性:解釋一個UINavigationController

防止佔壓欄按鈕項目的創建在你的導航項目創造的你視圖控制器的觀點

我不明白這是什麼意思,有誰能夠詳細

回答

0

這可能是添加到文檔相當最近,我今天這個偶然發現首次解釋。此外,幾乎所有我看到的按鈕初始化的示例代碼都發生在viewDidLoad方法中 - 根據引用的語句,顯然這不是最好的選擇。

蘋果公司對我們說的是,當viewDidLoad方法尚未執行或根本沒有執行時,可能會出現導航項的內容被請求的情況。 當您一次推送多個視圖控制器時會發生這種情況。例如。通過使用setViewControllers:動畫:接口或通過做這樣的事情:

ViewController1 *firstViewController = [[ViewController1 alloc] init]; 
ViewController2 *secondViewController = [[ViewController2 alloc] init]; 
[navigationController pushViewController:firstViewController animated:YES]; 
[navigationController pushViewController:secondViewController animated:YES]; 

在這種情況下firstViewController的viewDidLoad方法將不會被調用,直到用戶導航回去吧。如果您已將標題屬性設置爲firstViewController,那麼您會希望後退按鈕標有您在firstViewController中設置的標題。然而,後退按鈕將被稱爲「後退」,因爲當UINavigationController請求時,firstViewController的標題屬性爲零。

得出的結論是:搭售欄按鈕項目的創建創建視圖的適用於大多數情況。不過請記住,您可以在有或沒有創建視圖的情況下,在需要導航項信息的情況下使用。在這種情況下,考慮在viewcontrollers 初始化方法初始化navigationItem財產。

相關問題