导航控制器

利用UINavigationController,可以轻松地管理多个控制器,轻松完成控制器之间的切换,典型例子就是系统自带的“设置”应用

UINavigationController的使用步骤

  • 初始化UINavigationController
  • 设置UIWindow的rootViewController为UINavigationController
  • 根据具体情况,通过push方法添加对应个数的子控制器

使用push方法能将某个控制器压入栈

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated;

使用pop方法可以移除控制器

将栈顶的控制器移除
- (UIViewController *)popViewControllerAnimated:(BOOL)animated;

回到指定的子控制器
- (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated;

回到根控制器(栈底控制器)
- (NSArray *)popToRootViewControllerAnimated:(BOOL)animated;

销毁一个控制器

[self dismissViewControllerAnimated:YES completion:nil];

或者采用循环的方法,听说这种方法挺有效

for (UIViewController *controller in self.navigationController.viewControllers) {if ([controller isKindOfClass:[你要跳转到的Controller class]]) {[self.navigationController popToViewController:controller animated:YES];}
}

导航栏

导航栏的内容由栈顶控制器的navigationItem属性决定,UINavigationItem有以下属性影响着导航栏的内容。
左上角的返回按钮
@property(nonatomic,retain) UIBarButtonItem *backBarButtonItem;

中间的标题视图
@property(nonatomic,retain) UIView *titleView;

中间的标题文字
@property(nonatomic,copy) NSString *title;

左上角的视图
@property(nonatomic,retain) UIBarButtonItem *leftBarButtonItem;

UIBarButtonItem *rightBarButtonItem  右上角的视图
@property(nonatomic,retain) UIBarButtonItem *rightBarButtonItem;

另外技巧

在View中获取当前导航栏

        // 假设 App 结构是 Root -> TabBar -> Navigation -> ViewControllerUITabBarController *tabBarControler = (id)[UIApplication.sharedApplication.delegate.window.rootViewController;UINavigationController *navigationController = tabBarControler.selectedViewController;

转载于:https://www.cnblogs.com/jys509/p/4825437.html

iOS UI基础-11.0 UINavigationController相关推荐

  1. iOS UI基础-6.0 UIActionSheet的使用

    UIActionSheet是在iOS弹出的选择按钮项,可以添加多项,并为每项添加点击事件. 使用 1.需要实现UIActionSheetDelegate  协议 @interface NJWisdom ...

  2. iOS UI基础-7.0 UIScrollView

    概述 移动设备的屏幕大小是极其有限的,因此直接展示在用户眼前的内容也相当有限.当展示的内容较多,超出一个屏幕时,用户可通过滚动手势来查看屏幕以外的内容,普通的UIView不具备滚动功能,不能显示过多的 ...

  3. pod install 时遇到 Automatically assigning platform `iOS` with version `11.0` on target XXX......

    pod install的时候遇到的问题: [!] CDN: trunk Repo update failed - 2 error(s): CDN: trunk URL couldn't be down ...

  4. iOS UI基础-4.1应用程序管理 字典转Model

    用模型取代字典 使用字典的坏处 一般情况下,设置数据和取出数据都使用"字符串类型的key",编写这些key时,编辑器没有智能提示,需要手敲 dict[@"name&quo ...

  5. iOS开发UI基础—手写控件,frame,center和bounds属性

    iOS开发UI基础-手写控件,frame,center和bounds属性 一.手写控件 1.手写控件的步骤 (1)使用相应的控件类创建控件对象 (2)设置该控件的各种属性 (3)添加控件到视图中 (4 ...

  6. IOS开发基础之UI基础的团购源码完整版本

    IOS开发基础之UI基础的团购源码完整版本 // // ViewController.m // 17-团购案例 // // Created by 鲁军 on 2021/2/4. //#import & ...

  7. IOS开发之UI基础LOL英雄展示-15

    IOS开发之UI基础LOL英雄展示-15 // // ViewController.m // 15-英雄展示-单组数据 // // Created by 鲁军 on 2021/2/3. //#impo ...

  8. IOS开发基础之UI的喜马拉雅的项目-10

    IOS开发基础之UI的喜马拉雅的项目-10 // // ViewController.m // 10-喜马拉雅 // // Created by 鲁军 on 2021/2/2. //#import & ...

  9. IOS UI开发基础之超级猜图完整版本-08

    IOS UI开发基础之超级猜图完整版本-08 // // ViewController.m // 09-超级猜图 // // Created by 鲁军 on 2021/1/31. //#import ...

最新文章

  1. flash玩转cookie
  2. es6 --- 自制迭代器
  3. Xcode缓存数据清除
  4. l2-006 树的遍历
  5. Python 命令行库的大乱
  6. zephir 编译php,使用Zephir来快速编写高性能PHP二进制拓展
  7. 用java做登录界面_求用JAVA编写的登陆界面!
  8. Oracle统计信息锁,oracle 由于impdp 引起的表统计信息被锁 ORA-20005: object statistics are locked...
  9. VC:CString用法整理
  10. Git和Github详细教程
  11. mysql 查出数据后插入新建表
  12. mysql创建数据库sql语句_创建数据库的SQL语句:mysql数据库
  13. 阿里云盘——新的屠龙勇士?
  14. webgl 地球_使用WebGL和JavaScript构建地球
  15. MAC通过HDMI转VGA转接头连接显示器
  16. android节日接口,节假日api及其整合
  17. dns找不到服务器,“找不到服务器或DNS错误”,如何调整?
  18. HDU 2197 本源串
  19. rsync下行同步和inotify实时同步部署
  20. Centos8 开启Telnet服务

热门文章

  1. 19-7-15学习笔记
  2. 网络推广中网络推广专员如何培养与搜索引擎的友好度和信任度
  3. python字符串打印教学_python字符串格式化教你正确打印 : D
  4. Linux下的几款svn gui工具
  5. 开发日记-20190801 读书笔记《Linux 系统管理技术手册(第二版)》关键词logrotate 管理日志文件
  6. 16年寒假随笔(2)
  7. Trie(前缀树/字典树)及其应用
  8. 基于矩阵分解的推荐算法,简单入门
  9. 深度学习在gilt应用——用图像相似性搜索引擎来商品推荐和服务属性分类
  10. JavaScript EventLoop