NavigationController & TabBarController都是界面控制的方式铐料,在使用上感覺很近似渐裂,因此就把它們的筆記放在一起了。
Navigation Bar
Navigation Bar:最常用的界面跳轉(zhuǎn)控制方法之一
每個被管理的View Controller要提供:
- 內(nèi)容
- 導(dǎo)航欄標題
- 導(dǎo)航欄上額外按鍵
- 工具欄(可選)按鍵
圖示
navigation_interface
nav_controllers_objects
結(jié)構(gòu):管理的VC钠惩,公共界面柒凉、Delegate
Lifecycle
- 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
UINavigationBar
UIBarButtonItem,UIBarButtonSystemItem
UITabBarController
一種分頁的方法
圖示
UITabBarController的結(jié)構(gòu)
代碼
//創(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;