UITabBarController 和 UINavigationController 的详解
首先得搞清這兩個控制器之間的層級關(guān)系,我們直接看官網(wǎng)給的圖,如下所示:
從這張圖可以看到:最右邊的Assembled views是呈現(xiàn)給用戶的界面,它左邊的Window是最底層的窗口,重點來了,再往左,是Tab bar view,Tab bar view的上方是Navigation view,最后是用戶定制的視圖。
看完這個,代碼就應(yīng)該很好寫了,我們需要把Navigation view加到 Tab bar view的內(nèi)容上去,Tab bar view再加到Window上去。就是Window套UITabBarController,UITabBarController套UINavigationController, UINavigationController套UIViewController。
UIViewControlleller ?的tabBarItem的詳情里面最后一句話:?
The default value is a tab bar item that displays the view controller'€?s title.
標簽欄元素默認顯示的是 視圖控制器的標題。
navigationItem?里面同樣有這么一句話
The default behavior is to create a navigation item that displays the view controller'€?s title.
默認創(chuàng)建一個導(dǎo)航欄元素顯示 視圖控制器的標題
1.因此?activetyLC.title = @"活動"; 同時給導(dǎo)航欄和標簽欄賦值 ?就有跡可循了。
2. 若 我們的導(dǎo)航欄標題 和標簽欄 標題顯示的不一樣的時候如何賦值呢。?
UIViewController是UINavigationController和 UITabBarController的父類
我們看下UIViewController里面的navigationItem 和 tabBarItem 是如何說明的
?
The tab bar item that represents the view controller when added to a tab bar controller.
標簽欄元素 代表 控制器被 ?添加到的標簽欄控制器 的標簽欄元素 (父標簽欄 標簽元素)
The navigation item used to represent the view controller in a parent'€?s navigation bar. (read-only)
導(dǎo)航欄元素代表著 父視圖控制器的導(dǎo)航欄 元素 (父 導(dǎo)航欄 導(dǎo)航元素)
?
按照上面我所說的層次關(guān)系,在 最上層的 UIViewController
這樣寫:
?self.navigationItem.title?=?@"活動";
?
??self.tabBarItem.title?=?@"活動123"; ?會如何??
結(jié)果是: 導(dǎo)航欄 標題 顯示 ?“活動” ,標簽欄為 “空”。
若我們給導(dǎo)航欄的 tabBarItem 賦值。
activetyNC.tabBarItem.title = @"活動";
則 標簽欄 正常顯示 “活動”。?
結(jié)合上面的 UIViewController里面對 導(dǎo)航元素和 標簽元素的 介紹。 這樣就明白了。
雖然?
UINavigationController和 UITabBarController 都繼承自 UIViewController,他們中都有 標簽元素和導(dǎo)航元素屬性,但是
對于:UIViewController navigationItem 和 tabBarItem 沒有賦值,則為空,若父視圖為導(dǎo)航欄控制器,navigationItem為 導(dǎo)航欄控制器的 navigationItem; 若父類為 標簽控制器,則 tabBarItem為 標簽控制器的 tabBarItem。
?
轉(zhuǎn)載于:https://www.cnblogs.com/mafeng/p/5698691.html
總結(jié)
以上是生活随笔為你收集整理的UITabBarController 和 UINavigationController 的详解的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Navicat Premium mys
- 下一篇: 架构实例之Demo_JSP