作者guninia (努力工作賺錢)
看板MacDev
標題Re: [問題] navigation + tabbar
時間Tue Oct 1 10:24:32 2013
※ 引述《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
推 ahchie:推~ 10/01 11:02
推 xyziscariot:好文!不推不行~ 10/01 11:41
推 xu35p4jo6:推~ 10/01 11:49
推 issuemylove:猛啊 推一個QQ 10/02 18:26
→ tom19830924:雖然有點馬後砲 不過還是說一下 其實拉一拉storyboard 10/04 11:00
→ tom19830924:就可以用圖形式來瞭解他在講啥 10/04 11:01
→ tom19830924:一是用NavCtr然後rootView設TabBarCtr 在對TabBarCtr 10/04 11:02
→ tom19830924:分別拉各個ViewCtr 10/04 11:03
→ tom19830924:另一種就是先拉TabBarCtr出來 然後在拉NavCtr 然後 10/04 11:04
→ tom19830924:NavCtr的rootView設ViewCtr 然後再把TabBarCtr連到 10/04 11:05
→ tom19830924:NavBarCtr去 重複動作 10/04 11:06
→ tom19830924:這也是為啥我喜歡storyboard的原因 很直覺就完成 10/04 11:06