Re: [問題] navigation + tabbar

看板MacDev作者 (努力工作賺錢)時間10年前 (2013/10/01 10:24), 編輯推噓4(408)
留言12則, 5人參與, 最新討論串2/2 (看更多)
※ 引述《issuemylove (skill)》之銘言: : 各位大大好 : 想請問 navigation + tabbar 的情況下 : 我想要 navigation bar 上增加 subview : 我看範例是在 tab item 對應的 view controller 上寫下 : self.tabBarController.navigationController.navigation addSubView: myView]; : 即可增加 subview : 可是我怎樣都試不出來呀QQ... : 一直都沒有 view 產生 也沒 error message : 還是我有甚麼先決條件沒看到嗎? : 謝謝! tabBarController跟navigationController結合的方式有兩種, 第一種是以UITabBarController控管UINavigationController: UIViewController設定為UINavigationController的rootViewController, 然後以NSArray包裝數個UINavigationController後, 再用[tabBarController setViewControllers:array animated:animatedOrNot], 這樣的方式結合。 如此狀況下想要在navigationBar上面新增物件, 那麼就在當前的UIViewController下: self.navigationItem 或是 self.navigationController.navigationBar 就可以操作到當前畫面上的navigationBar了。 第二種是以UINavigationController控管UITabBarController: 以NSArray包裝數個UIViewController後, 再用[tabBarController setViewControllers:array animated:animatedOrNot], 然後再將tabBarController設定為navigationController的rootViewController。 這樣的情況下, self.tabBarController.navigationItem 或是 self.tabBarController.navigationController.navigationBar 應該可以操作到當前畫面上的navigationBar。 另外,你也可以檢查你要顯示的navigationController是不是你要的那ㄧ個。 我會在我想像中的那個navigationController在alloc init之後, 用 NSLog(@"navigationController[%p] allocated and init", navigationController); 去印出這個navigationController的指標位置, 然後再到你取用這個navigationController的地方, NSLog(@"navigationController[%p]", self.xxxxxx.navigationController); 去印出這個navigationController的指標位置,並比對兩者是否相同。 「xxxxxx」根據你建立navigationController的結構(如上面兩種所述)會有不同。 以上供您參考。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.133.47.18

10/01 11:02, , 1F
推~
10/01 11:02, 1F

10/01 11:41, , 2F
好文!不推不行~
10/01 11:41, 2F

10/01 11:49, , 3F
推~
10/01 11:49, 3F

10/02 18:26, , 4F
猛啊 推一個QQ
10/02 18:26, 4F

10/04 11:00, , 5F
雖然有點馬後砲 不過還是說一下 其實拉一拉storyboard
10/04 11:00, 5F

10/04 11:01, , 6F
就可以用圖形式來瞭解他在講啥
10/04 11:01, 6F

10/04 11:02, , 7F
一是用NavCtr然後rootView設TabBarCtr 在對TabBarCtr
10/04 11:02, 7F

10/04 11:03, , 8F
分別拉各個ViewCtr
10/04 11:03, 8F

10/04 11:04, , 9F
另一種就是先拉TabBarCtr出來 然後在拉NavCtr 然後
10/04 11:04, 9F

10/04 11:05, , 10F
NavCtr的rootView設ViewCtr 然後再把TabBarCtr連到
10/04 11:05, 10F

10/04 11:06, , 11F
NavBarCtr去 重複動作
10/04 11:06, 11F

10/04 11:06, , 12F
這也是為啥我喜歡storyboard的原因 很直覺就完成
10/04 11:06, 12F
文章代碼(AID): #1IIZ9aRc (MacDev)
討論串 (同標題文章)
文章代碼(AID): #1IIZ9aRc (MacDev)