簡體   English   中英

單擊時從一個標簽欄移動到另一個標簽欄(帶有導航控制器的標簽欄)

[英]Move from one tab bar to another on click (Tab bar with navigation controllers)

大家好我想從第一個tabbarcontroller到第二個tabbarcontroller但不能這樣做。 我的TabBar中的View Controllers也嵌入了NavigationControllers,所以當我嘗試切換標簽時,它給出了錯誤說 - :

無法將'UINavigationController'類型的值(0x1048d5898)轉換為'abc.CategoriesController'(0x101088d88)。

我使用的代碼 - :

 let barViewControllers = self.tabBarController?.viewController
 let svc = barViewControllers![1] as! myController
 svc.myOrder = self.myOrder

我嘗試了很多解決方案,但是沒有人能幫助我嗎? 如果有人可以,請解釋我背后的概念嗎?

self.tabBarController.selectedIndex = 1確實有效但我無法使用此方法傳遞數據。

正如Maddy所說:

使用let barViewControllers = self.tabBarController?.viewController[1] as? myController let barViewControllers = self.tabBarController?.viewController[1] as? myController傳遞數據。

但這就是讓我崩潰的路線

你得到的錯誤表明你從下面的代碼得到的不是viewController,如果你

let barViewControllers = self.tabBarController?.viewController //some what wrong with this

訪問所有視圖控制器的最佳方法如下

var svc = self.tabBarController.viewControllers

如果你想通過索引訪問viewControllers然后低於一個

var svc = self.tabBarController.viewControllers[1] as yourVC

如果要從標簽欄訪問導航控制器,請在列表中輸入最后但不在列表中

var svc = self.tabBarController.viewControllers[1] as UINavigationController

希望這對你有所幫助:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM