iOS-OC初级ios

iOS应用开发实战(10-13)-NavigationContr

2016-03-09  本文已影响120人  逸飞u

NavigationController & TabBarController都是界面控制的方式,在使用上感觉很近似,因此就把它们的笔记放在一起了。

Navigation Bar

Navigation Bar:最常用的界面跳转控制方法之一
每个被管理的View Controller要提供:

图示

navigation_interface

navigation_interface_2x.png

nav_controllers_objects

nav_controllers_objects.jpg

结构:管理的VC,公共界面、Delegate

结构.jpg

Lifecycle

nav_controller_notifications.png

在代码中使用导航

创建

- (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.

跳转

- (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:

设置和控制

@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结构.jpg

UIBarButtonItem,UIBarButtonSystemItem

UIBarButtonItem.png

UITabBarController

一种分页的方法

图示

tabbar_compare.jpg

UITabBarController的结构

结构.png

代码

//创建
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;

界面定制

上一篇下一篇

猜你喜欢

热点阅读