我需要確定UIViewController
之前在UINavigationController
中顯示的內容。我的導航是3級深度,2級我需要確定我是從1級推進到這裏還是從3級突然到達這裏。我怎麼能輕鬆做到這一點?iOS - 確定UIViewController之前在UINavigationController中顯示的內容
5
A
回答
4
落實UINavigationControllerDelegate方法:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
,並對其進行查詢,找出當前顯示視圖控制器:
navigationController.topViewController
這是你的出發點之一。
3
您可以通過使用viewControllers屬性來查看整個UINavigationController堆棧。
int count = [navigationController.viewControllers count];
topController = [navigationController.viewControllers objectAtIndex:count - 1];
previousController = [navigationController.viewControllers objectAtIndex:count - 2];
//...
//...
rootController = [navigationController.viewControllers objectAtIndex: count - count];
2
iOS 5.0添加了[UIViewController isMovingToParentViewController]。在viewWillAppear
和viewDidAppear
期間,如果您來自較低編號的視圖控制器,則返回YES
,否則返回NO
。這個名字很不幸讓人困惑 - 你會認爲[UIViewController isMovingFromParentViewController]是正確的調用方法。
但是,代表所有第二代設備都停留在iOS 4.2.1上的小型機,除非真的必須使用iOS 5功能。
相關問題
- 1. 如何在UIViewController從UINavigationController彈出之前顯示警報
- 2. ios uinavigationcontroller到uiviewcontroller
- 3. UITableView在UIViewController中不顯示內容
- 4. iOS在顯示之前如何設置UIViewController的視圖框架?
- 5. 在UINavigationController上設置toolbarItems屬性,或者在UINavigationController中顯示UIViewController?
- 6. :在CSS中定義的內容顯示不同之前
- 7. 在顯示HTML5之前加載內容
- 8. 當UIPopover中顯示UINavigationController內容偏移
- 9. 在容器中顯示UIViewController
- 10. 如何在jQuery中顯示內容之前顯示setTimeout圖片?
- 11. IE8之前的內容不顯示
- 12. 確定iframe中顯示的內容
- 13. iOS 6 - 在UINavigationController中強制旋轉UIViewController
- 14. WebView未正確顯示內容iOS
- 15. iPhone的UINavigationController內的UIViewController
- 16. 在顯示內容之前顯示進度對話框
- 17. 打開UIViewController,不顯示UINavigationController導航欄
- 18. iOS版 - 的UINavigationController之前的UITabBarController
- 19. 在UINavigationController中只處理UIViewController
- 20. UIWebView中不顯示在IOS內容
- 21. 在顯示WordPress內容之前有條件檢查前一頁
- 22. 如何在顯示內容之前顯示內容圖像不加載的隱藏內容?
- 23. 在UIPopoverController內顯示UIViewController
- 24. 如何在Wordpress中顯示頁面內容之前添加內容
- 25. IFRAME內容的iframe外顯示在iOS
- 26. 確定是否顯示dijit.dialog內容
- 27. 當UIViewController在UINavigationController中時,鍵盤沒有顯示出來
- 28. 在畫像中顯示一個橫向UIViewController UITabBarController/UINavigationController
- 29. JQuery Ajax:舊內容在顯示加載的內容之前彈出
- 30. 如何在顯示之前填充加載的內容?
我可能很笨,但我不明白。我在我的2級viewcontroller中實現了'UINavigationControllerDelegate'方法。當我NSLog(@「%@」,navigationController.topViewController);''我剛剛得到當前正在顯示的'UIViewController'(2級)(不是我導航的3級視圖控制器或1級視圖控制器)。 – 2012-02-10 19:28:11
@PeterWarbo你不傻,我是。對於那個很抱歉。有沒有簡單的方法,但這是一個應該工作的方法。無論什麼類實例化您的導航控制器,都將其設置爲navigationController.topViewController屬性的KVO(鍵值觀察者)。每當此屬性更改時,它將調用observeValueForKeyPath:並提供上下文參數中的更改字典。從這裏你可以確定舊值是什麼。 – Rayfleck 2012-02-10 20:42:08