iOS應(yīng)用開發(fā)實戰(zhàn)(10-13)-NavigationController & TabBarController

NavigationController & TabBarController都是界面控制的方式铐料,在使用上感覺很近似渐裂,因此就把它們的筆記放在一起了。

Navigation Bar

Navigation Bar:最常用的界面跳轉(zhuǎn)控制方法之一
每個被管理的View Controller要提供:

  • 內(nèi)容
  • 導(dǎo)航欄標題
  • 導(dǎo)航欄上額外按鍵
  • 工具欄(可選)按鍵

圖示

navigation_interface

navigation_interface_2x.png

nav_controllers_objects

nav_controllers_objects.jpg

結(jié)構(gòu):管理的VC钠惩,公共界面柒凉、Delegate

結(jié)構(gòu).jpg

Lifecycle

nav_controller_notifications.png
  • Tip:傳遞數(shù)據(jù)建議用Segue方法

在代碼中使用導(dǎo)航

創(chuàng)建

- (instancetype)initWithRootViewController:(UIViewController *)rootViewController; // Convenience method pushes the root view controller without animation.
- (instancetype)initWithNavigationBarClass:(nullable Class)navigationBarClass toolbarClass:(nullable Class)toolbarClass;
- (void)setViewControllers:(NSArray<UIViewController *> *)viewControllers animated:(BOOL)animated ; // If animated is YES, then simulate a push or pop depending on whether the new top view controller was previously in the stack.

跳轉(zhuǎn)

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated; // Uses a horizontal slide transition. Has no effect if the view controller is already in the stack.
- (nullable UIViewController *)popViewControllerAnimated:(BOOL)animated; // Returns the popped controller.
- (nullable NSArray<__kindof UIViewController *> *)popToRootViewControllerAnimated:(BOOL)animated; // Pops until there's only a single view controller left on the stack. Returns the popped controllers.
- (nullable NSArray<__kindof UIViewController *> *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated; // Pops view controllers until the one specified is on top. Returns the popped controllers.
- (void)showViewController:(UIViewController *)vc sender:(nullable id)sender ; // Interpreted as pushViewController:animated:

設(shè)置和控制

@property(nullable, nonatomic, weak) id<UINavigationControllerDelegate> delegate;
@property(nonatomic,copy) NSArray<__kindof UIViewController *> *viewControllers; // The current view controller stack.
@property(nonatomic,readonly) UINavigationBar *navigationBar; // The navigation bar managed by the controller. Pushing, popping or setting navigation items on a managed navigation bar is not supported.
@property(null_resettable,nonatomic,readonly) UIToolbar ; // For use when presenting an action sheet.

界面定制

Demo:helloNavUI

helloNavUI.png

UINavigationBar

NavigationBar結(jié)構(gòu).jpg

UIBarButtonItem,UIBarButtonSystemItem

UIBarButtonItem.png

UITabBarController

一種分頁的方法

圖示

tabbar_compare.jpg

UITabBarController的結(jié)構(gòu)

結(jié)構(gòu).png

代碼

//創(chuàng)建
UITabBarController *vc =[[UITabBarController alloc]init];
vc.tabBarItem=[[UITabBarItem alloc]initWithTitle:@"HOME" image:@"first" tag:0];

//管理
[self.tabBarController setViewControllers:@"FirstViewController" animated:YES];

//add
[self.view addSubview:vc];

//選中
vc.selectedViewController =vc;
vc.selectedIndex = 1;

界面定制

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市篓跛,隨后出現(xiàn)的幾起案子膝捞,更是在濱河造成了極大的恐慌,老刑警劉巖愧沟,帶你破解...
    沈念sama閱讀 216,843評論 6 502
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件蔬咬,死亡現(xiàn)場離奇詭異,居然都是意外死亡沐寺,警方通過查閱死者的電腦和手機林艘,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,538評論 3 392
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來混坞,“玉大人狐援,你說我怎么就攤上這事“蔚冢” “怎么了咕村?”我有些...
    開封第一講書人閱讀 163,187評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長蚊俺。 經(jīng)常有香客問我懈涛,道長,這世上最難降的妖魔是什么泳猬? 我笑而不...
    開封第一講書人閱讀 58,264評論 1 292
  • 正文 為了忘掉前任批钠,我火速辦了婚禮宇植,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘埋心。我一直安慰自己指郁,他們只是感情好,可當我...
    茶點故事閱讀 67,289評論 6 390
  • 文/花漫 我一把揭開白布拷呆。 她就那樣靜靜地躺著闲坎,像睡著了一般。 火紅的嫁衣襯著肌膚如雪茬斧。 梳的紋絲不亂的頭發(fā)上腰懂,一...
    開封第一講書人閱讀 51,231評論 1 299
  • 那天,我揣著相機與錄音项秉,去河邊找鬼绣溜。 笑死,一個胖子當著我的面吹牛娄蔼,可吹牛的內(nèi)容都是我干的怖喻。 我是一名探鬼主播,決...
    沈念sama閱讀 40,116評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼岁诉,長吁一口氣:“原來是場噩夢啊……” “哼锚沸!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起涕癣,我...
    開封第一講書人閱讀 38,945評論 0 275
  • 序言:老撾萬榮一對情侶失蹤咒吐,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后属划,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體恬叹,經(jīng)...
    沈念sama閱讀 45,367評論 1 313
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,581評論 2 333
  • 正文 我和宋清朗相戀三年同眯,在試婚紗的時候發(fā)現(xiàn)自己被綠了绽昼。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,754評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡须蜗,死狀恐怖硅确,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情明肮,我是刑警寧澤菱农,帶...
    沈念sama閱讀 35,458評論 5 344
  • 正文 年R本政府宣布,位于F島的核電站柿估,受9級特大地震影響循未,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜秫舌,卻給世界環(huán)境...
    茶點故事閱讀 41,068評論 3 327
  • 文/蒙蒙 一的妖、第九天 我趴在偏房一處隱蔽的房頂上張望绣檬。 院中可真熱鬧,春花似錦嫂粟、人聲如沸娇未。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,692評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽零抬。三九已至,卻和暖如春宽涌,著一層夾襖步出監(jiān)牢的瞬間媚值,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,842評論 1 269
  • 我被黑心中介騙來泰國打工护糖, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人嚼松。 一個月前我還...
    沈念sama閱讀 47,797評論 2 369
  • 正文 我出身青樓嫡良,卻偏偏與公主長得像,于是被迫代替她去往敵國和親献酗。 傳聞我的和親對象是個殘疾皇子寝受,可洞房花燭夜當晚...
    茶點故事閱讀 44,654評論 2 354

推薦閱讀更多精彩內(nèi)容