iOS开发-UINavigationController简单介绍
导航条或者说导航栏目现在在App中基本上也算是标配,类似于父子级别的味道在里面,UINavigationController就是负责简化这一实现功能的,属于iOS开发中比较常用的一种容器View controller,很多人都用,实现起来相对比较容易,可以先看张图片了解NavigationController:

界面布局
上面看着很高大上,下面看个个人的,从控件库中拖入一个Navigation Controller,然后新建两个ViewController:

拖入的一个NavigationController可以直接使用,需要演示,后面有多加了一个View:

Demo实现
主页的ViewController中初始化一下数据:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
data=[[NSArray alloc] initWithObjects:@"前端",@"后端",nil];
[self.tableView setDelegate:self];
[self.tableView setDataSource:self];
}
设置组数,行数和内容:
}
//分组的数量
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
} //分组的行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [data count];
}
//返回TableCell中内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil]; [cell.textLabel setText:data[indexPath.row]]; return cell;
}
设置行高:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 40;
}
设置跳转事件:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSArray *notificationData=[[NSArray alloc]init];
NSInteger index=[self.tableView indexPathForSelectedRow].row;
if (index==0) {
notificationData=[[NSArray alloc]initWithObjects:@"Android",@"iOS",@"JS",nil];
}else{
notificationData=[[NSArray alloc]initWithObjects:@"Java",@"C#",@"Python",nil];
}
SecondViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"SecondStoryID"];
controller.data=notificationData;
[self.navigationController pushViewController:controller animated:YES];
}
详情的ViewController和第一个类似,之前已经写过很多TableView的实现,直接贴代码,就不一一解释:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)notificationHandler:(NSNotification *)notification{
self.data=[notification object];
}
//分组的数量
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
//分组的行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [self.data count];
}
//返回TableCell中内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
[cell.textLabel setText:self.data[indexPath.row]];
NSLog(@"%@",self.data[indexPath.row]);
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 40;
}
不过详情的头文件中要设置一下:
@interface SecondViewController : UIViewController @property (nonatomic,strong) NSArray *data; @end
最终实现的效果如下:

绿色背景的导航条需要个人设置:

iOS开发-UINavigationController简单介绍的更多相关文章
- iOS开发-UIActionSheet简单介绍
UIActionSheet和UIAlertView都是ios系统自带的模态视图,模态视图的一个重要的特性就是在显示模态视图的时候可以阻断其他视图的事件响应.一般情况下我们对UIAlertView使用的 ...
- IOS开发之简单音频播放器
今天第一次接触IOS开发的UI部分,之前学OC的时候一直在模拟的使用Target-Action回调模式,今天算是真正的用了一次.为了熟悉一下基本控件的使用方法,和UI部分的回调,下面开发了一个特别简易 ...
- [翻译] iOS开发工具的介绍(第一部分)
IOS DEVELOPMENT TIPS & TRICKS - PART I http://blog.trifork.com/2013/12/19/ios-development-tips-t ...
- 【iOS】Quartz2D简单介绍
一.什么是Quartz2D Quartz 2D是⼀个二维绘图引擎,同时支持iOS和Mac系统 Quartz 2D能完成的工作: 绘制图形 : 线条\三角形\矩形\圆\弧等 绘制文字 绘制\生成图片(图 ...
- iOS沙盒简单介绍
先简单介绍一下什么是沙盒:你可以简单理解成为一个目录,这个目录的改动不会对操作系统造成任何损失.(这里也有一点点介绍) 看看苹果的沙盒目录: 再附一张苹果官方的图 一个iOS app操作都是在自己的沙 ...
- Linux 内核开发—内核简单介绍
内核简单介绍 Linux 构成 Linux 为什么被划分为系统空间和内核空间 隔离核心程序和应用程序,实现对核心程序和数据的保护. 什么内核空间,用户空间 内核空间和用户空间是程序执行的两种不同的状态 ...
- ios开发杂项(基础性介绍等)
IOS Xcode开发中的文件后缀名区别m,mm,cpp,h .h :头文件.头文件包含类,类型,函数和常数的声明. .m :源代码文件.这是典型的源代码文件扩展名,可以包含Objective-C和C ...
- iOS DeepLinkKit使用简单介绍
Update: 2017.04.08 添加了使用iOS DeepLinkKit使用Universal Links的部分 ---------------------------------------- ...
- ios开发--GCD使用介绍:4-延迟执行操作
在开发过程中,我们有时会希望把一些操作封装起来延迟一段时间后再执行.iOS开发中,有两种常用的方法可以实现延迟执行,一种是使用GCD,另外一种是使用NSRunLoop类中提供的方法. 1.使用GCD实 ...
随机推荐
- JAVA单向链表实现
JAVA单向链表实现 单向链表 链表和数组一样是一种最常用的线性数据结构,两者各有优缺点.数组我们知道是在内存上的一块连续的空间构成,所以其元素访问可以通过下标进行,随机访问速度很快,但数组也有其缺点 ...
- CSU - 2055 Wells‘s Lottery
Description As is known to all, Wells is impoverished. When God heard that, God decide to help the p ...
- 洛谷——P1747 好奇怪的游戏
P1747 好奇怪的游戏 题目背景 <爱与愁的故事第三弹·shopping>娱乐章. 调调口味来道水题. 题目描述 爱与愁大神坐在公交车上无聊,于是玩起了手机.一款奇怪的游戏进入了爱与愁大 ...
- 解决python2.x文件读写编码问题
转自: https://xrlin.github.io/%E8%A7%A3%E5%86%B3python2.x%E6%96%87%E4%BB%B6%E8%AF%BB%E5%86%99%E7%BC%96 ...
- [PE484]Arithmetic Derivative
题意:对整数定义求导因子$'$:$p'=1,(ab)'=a'b+ab'$,求$\sum\limits_{i=2}^n(i,i')$ 这个求导定义得比较妙:$(p^e)'=ep^{e-1}$ 推一下就可 ...
- Lunix/Mac下根据最后修改时间复制文件和文件夹,保持原有的目录结构
度娘知道:http://zhidao.baidu.com/link?url=DD47jm6qDgT7yxsnz9e-NC4Fqd33oRoiIwcGLkw5TL4cbf50VKY2IONbHKH0IE ...
- bzoj 1027 floyd求有向图最小环
结合得好巧妙.... 化简后的问题是: 给你两个点集A,B,求B的一个子集BB,使得BB的凸包包含A的凸包,求BB的最小大小. 先特判答案为1,2的情况,答案为3的情况,我们先构造一个有向图: 对于B ...
- setTimeout 第一个参数类型
读别人代码的时候看到这么一段,很不理解,然后就搜了一下百度 setTimeout / setInterval 第一个参数可以有三种类型: 字符串 . methods . 匿名函数 1.字符串 ...
- Codeforces Round #297 (Div. 2)D. Arthur and Walls 暴力搜索
Codeforces Round #297 (Div. 2)D. Arthur and Walls Time Limit: 2 Sec Memory Limit: 512 MBSubmit: xxx ...
- Get started with IDA and disassembly SH7058
http://www.romraider.com/forum/viewtopic.php?f=25&t=6303 All of the 16-bit guidance in the follo ...