iOS边练边学--UINavigationController导航条的使用
一、使用UINavigationController的步骤以及代码
// 程序加载完成后执行的代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// 1.初始化窗体
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // 2.导航控制器的根控制器
UIViewController *vc = [[ViewController alloc] init];
vc.view.backgroundColor = [UIColor lightGrayColor];
// 3.窗体的根控制器为导航控制器
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc]; // 4.设置窗体根控制器
self.window.rootViewController = nav; // 5.显示窗体
[self.window makeKeyAndVisible];
return YES;
}
@property(nonatomic,copy) NSArray *viewControllers;
@property(nonatomic,readonly) NSArray *childViewControllers;
<2>使用push方法能将某个控制器压入栈
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated;
<3>使用pop方法可以移除控制器
- (UIViewController *)popViewControllerAnimated:(BOOL)animated;
- (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated;
- (NSArray *)popToRootViewControllerAnimated:(BOOL)animated;
三、如何修改导航栏的内容
@property(nonatomic,retain) UIBarButtonItem *backBarButtonItem;
@property(nonatomic,retain) UIView *titleView;
@property(nonatomic,copy)NSString *title;
@property(nonatomic,retain) UIBarButtonItem *leftBarButtonItem;
@property(nonatomic,retain) UIBarButtonItem *rightBarButtonItem;
<6>代码实现:
- (void)viewDidLoad {
[super viewDidLoad];
// 这段代码是错误的!--导航栏的内容由栈顶控制器的navigationItem属性决定,并不是有导航栏本身决定!
// self.navigationController.navigationItem.title = @"第一个导航";
self.navigationItem.title = @"第一个导航";
// 下面这一句跟上面的代码是同一个意思,简化写法
// self.title = @"这个管那里????";
// 可以设置UIView
self.navigationItem.titleView = [UIButton buttonWithType:UIButtonTypeContactAdd];
// 左右两边的按钮系统默认渲染成蓝色的,并且位置改动不了
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"没用" style:UIBarButtonItemStyleDone target:nil action:nil];
// 右边按钮不受系统渲染的方法一:initWithCustomView
UIButton *btn = [[UIButton alloc] init];
[btn setImage:[UIImage imageNamed:@"navigationbar_friendsearch"] forState:UIControlStateNormal];
[btn setImage:[UIImage imageNamed:@"navigationbar_friendsearch_highlighted"] forState:UIControlStateHighlighted];
[btn sizeToFit];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
}

iOS边练边学--UINavigationController导航条的使用的更多相关文章
- UINavigationController导航条是否挡住下面的内容
控制 UINavigationController 导航条是否挡住下面的内容 if ([[[UIDevice currentDevice] systemVersion] floatValue] > ...
- Bootstrap每天必学之导航条
http://www.jb51.net/article/75534.htm Bootstrap每天必学之导航条,本文向大家讲解了多种多样的导航条,以及导航条中元素的实现方法,感兴趣的小伙伴们可以参考一 ...
- iOS边练边学--父子控件之作为导航控制器的子类产生的问题以及网易新闻练习
一.导航控制器的子类 作为导航控制器的子类,并且是导航控制器子类中的第一个,系统会默认给子控件添加EdgeInsert属性,把导航栏的宽度挤出来.但是系统只会默认修改第一个. 解决办法1:系统帮忙给第 ...
- IOS第12天(2,UINavigationController导航控制器)
****HMAppDelegate.m @implementation HMAppDelegate - (BOOL)application:(UIApplication *)application d ...
- iOS边练边学--Http网络再学习,简单介绍
一.URL 什么是URL URL中常见的协议 二.Http Http的基本通信过程 发送Http请求的方法 GET 和 POST 对比 GET 和 POST 的选择 三.iOS中的Http学习 iOS ...
- iOS边练边学--多线程NSOperation介绍,子类实现多线程的介绍(任务和队列),队列的取消、暂停(挂起)和恢复,操作依赖与线程间的通信
一.NSOperation NSOperation和NSOperationQueue实现多线程的具体步骤 先将需要执行的操作封装到一个NSOperation对象中 然后将NSOperation对象添加 ...
- iOS边练边学--多线程介绍、NSThread的简单实用、线程安全以及线程之间的通信
一.iOS中的多线程 多线程的原理(之前多线程这块没好好学,之前对多线程的理解也是错误的,这里更正,好好学习这块) iOS中多线程的实现方案有以下几种 二.NSThread线程类的简单实用(直接上代码 ...
- iOS边练边学--CALayer,非根层隐式动画,钟表练习
一.CALayer UIView之所以能显示在屏幕上,完全是因为他内部的一个图层 在创建UIView对象时,UIView内部会自动创建一个图层(即CALayer对象),通过UIView的layer属性 ...
- iOS边练边学--UIGestureRecognizer手势识别器简单介绍
iOS 3.2之后,苹果退出了手势识别功能(Gesture Recognizer),在触摸事件处理方面,大大简化了开发者的开发难度. 一.UIGestureRecognizer UIGestureRe ...
随机推荐
- Block全面分析
1.第一部分 定义和使用Block, 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 - (void)view ...
- 【LeetCode】127. Word Ladder
Word Ladder Given two words (start and end), and a dictionary, find the length of shortest transform ...
- android程序监听home键与电源键
01 private final BroadcastReceiver homePressReceiver = new BroadcastReceiver() { 02 final String SYS ...
- iOS - Analyze 静态分析
1.Analyze 使用 Xcode 自带的静态分析工具 Product -> Analyze(快捷键 command + shift + B)可以找出代码潜在错误,如内存泄露,未使用函数和变量 ...
- Python 元组 min() 方法
描述 Python 元组 min() 方法返回元组中元素最小值. 语法 min() 方法语法: min(T) 参数 T -- 指定的元组. 返回值 返回元组中元素最小值. 实例 以下实例展示了 min ...
- unity5 静态和动态cubmap
一,静态cubemap: asserts窗口 右键->Create->Legacy->Cubemap,新建一个cubemap,命名为cubeMap,然后为其各面指定贴图,如图: 需要 ...
- extjs中组件监听器里面的回调函数说明
近期在看项目源代码的时候发现了例如以下代码,当中_searchSupplierStore是JsonStore对象 _searchSupplierStore.on('beforeload',functi ...
- Scala之集合Collection
概述 Scala的集合类能够从三个维度进行切分: 可变与不可变集合(Immutable and mutable collections) 静态与延迟载入集合 (Eager and delayed ev ...
- ajaxfileupload异步上传附件添加參数的方法
1.js文件 // JavaScript Document jQuery.extend({ createUploadIframe: function(id, uri) { //create frame ...
- 特效effects(二)
CCActionInterval* createEffect(int nIndex, float t) { CCDirector::sharedDirector()->setDepthTest( ...