問題描述
我有一個使用導航控制器的 XCode iPad 項目.我試圖獲取一個按鈕來將 UISplitViewController 推送到導航堆棧,但收到此錯誤:
I have an XCode iPad project using a navigation controller. I tried to get a button to push a UISplitViewController to the navigation stack, but got this error:
拆分視圖控制器不能推送到導航控制器
Split View Controllers cannot be pushed to a Navigation Controller
原來 UISplitViewController 不能很好地與 UINavigationController 配合使用.但是,單擊此按鈕時,我仍然需要顯示拆分視圖控制器.我該怎么做呢?而且,同樣重要的是,如何制作后退按鈕以便用戶可以返回到導航控制器?
Turns out UISplitViewController doesn't play nicely with UINavigationController. However, I still need to show the split view controller when this button is clicked. How do I do this? And, also important, how do I make a back button so the user can be returned to the navigation controller?
推薦答案
要顯示 SplitViewController,您需要使用 setRootViewController.這是因為 SplitViewController 必須是根視圖控制器.
To display a SplitViewController you'll need to use setRootViewController. This is because a SplitViewController needs to be the root view controller.
來自 Apple 的文檔:
From Apple's Documentation:
拆分視圖控制器必須始終是您的任何界面的根創建.換句話說,您必須始終從UISplitViewController 對象作為應用程序的根視圖窗戶.然后,您的拆分視圖界面的窗格可能包含導航控制器、標簽欄控制器或任何其他類型的視圖你需要實現你的接口的控制器.
A split view controller must always be the root of any interface you create. In other words, you must always install the view from a UISplitViewController object as the root view of your application's window. The panes of your split-view interface may then contain navigation controllers, tab bar controllers, or any other type of view controller you need to implement your interface.
要返回,您需要使用 setRootViewController 返回之前的頁面.當我將我的 iPhone 應用程序轉換為通用應用程序時遇到了這個問題,最終我使用了 iPhone 的導航控制器和 iPad 版本的 setRootViewController.這有點令人遺憾,因為你不能很好地為它制作動畫不加一點修飾.
To get back you'll need to use setRootViewController to go back to the earlier page. I ran into this problem when I converted my iPhone app to universal, and ended up using a navigation controller for the iPhone and setRootViewController for the iPad version. It's a bit of a bummer because you can't animate it nicely without a bit of fudging.
這篇關于iOS:UISplitViewController 無法推送到 UINavigationController的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!