导航条或者说导航栏目现在在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简单介绍的更多相关文章

  1. iOS开发-UIActionSheet简单介绍

    UIActionSheet和UIAlertView都是ios系统自带的模态视图,模态视图的一个重要的特性就是在显示模态视图的时候可以阻断其他视图的事件响应.一般情况下我们对UIAlertView使用的 ...

  2. IOS开发之简单音频播放器

    今天第一次接触IOS开发的UI部分,之前学OC的时候一直在模拟的使用Target-Action回调模式,今天算是真正的用了一次.为了熟悉一下基本控件的使用方法,和UI部分的回调,下面开发了一个特别简易 ...

  3. [翻译] iOS开发工具的介绍(第一部分)

    IOS DEVELOPMENT TIPS & TRICKS - PART I http://blog.trifork.com/2013/12/19/ios-development-tips-t ...

  4. 【iOS】Quartz2D简单介绍

    一.什么是Quartz2D Quartz 2D是⼀个二维绘图引擎,同时支持iOS和Mac系统 Quartz 2D能完成的工作: 绘制图形 : 线条\三角形\矩形\圆\弧等 绘制文字 绘制\生成图片(图 ...

  5. iOS沙盒简单介绍

    先简单介绍一下什么是沙盒:你可以简单理解成为一个目录,这个目录的改动不会对操作系统造成任何损失.(这里也有一点点介绍) 看看苹果的沙盒目录: 再附一张苹果官方的图 一个iOS app操作都是在自己的沙 ...

  6. Linux 内核开发—内核简单介绍

    内核简单介绍 Linux 构成 Linux 为什么被划分为系统空间和内核空间 隔离核心程序和应用程序,实现对核心程序和数据的保护. 什么内核空间,用户空间 内核空间和用户空间是程序执行的两种不同的状态 ...

  7. ios开发杂项(基础性介绍等)

    IOS Xcode开发中的文件后缀名区别m,mm,cpp,h .h :头文件.头文件包含类,类型,函数和常数的声明. .m :源代码文件.这是典型的源代码文件扩展名,可以包含Objective-C和C ...

  8. iOS DeepLinkKit使用简单介绍

    Update: 2017.04.08 添加了使用iOS DeepLinkKit使用Universal Links的部分 ---------------------------------------- ...

  9. ios开发--GCD使用介绍:4-延迟执行操作

    在开发过程中,我们有时会希望把一些操作封装起来延迟一段时间后再执行.iOS开发中,有两种常用的方法可以实现延迟执行,一种是使用GCD,另外一种是使用NSRunLoop类中提供的方法. 1.使用GCD实 ...

随机推荐

  1. shell rename directory

    mv can do two jobs. It can move files or directories It can rename files or directories To just rena ...

  2. 深入理解mysql的自连接和join关联

    一.mysql自连接 mysql有时在信息查询时需要进行对自身连接(自连接),所以我们需要为表定义别名.我们举例说明,下面是商品采购表,我们需要找到采购价格比惠惠高的所有信息. 一般情况我们看到这张表 ...

  3. opencv 加载 修改 保存 图像

    #include <opencv2/opencv.hpp> #include <iostream> using namespace cv; /* 1 加载图像 cv::imre ...

  4. luoguP5108 仰望半月的夜空 [官方?]题解 后缀数组 / 后缀树 / 后缀自动机 + 线段树 / st表 + 二分

    仰望半月的夜空 题解 可以的话,支持一下原作吧... 这道题数据很弱..... 因此各种乱搞估计都是能过的.... 算法一 暴力长度然后判断判断,复杂度\(O(n^3)\) 期望得分15分 算法二 通 ...

  5. 【20181103T1】地球发动机【dp优化】

    题面 一眼dp 设\(f_i\)表示前\(i\)个且\(i\)必须选的最大功率 有 \(f _i= max_{1 \leq j < i,A_i - A_j > X_j} \{f_j \}+ ...

  6. 【洛谷】4180:【模板】严格次小生成树[BJWC2010]【链剖】【线段树维护最大、严格次大值】

    P4180 [模板]严格次小生成树[BJWC2010] 题目描述 小C最近学了很多最小生成树的算法,Prim算法.Kurskal算法.消圈算法等等.正当小C洋洋得意之时,小P又来泼小C冷水了.小P说, ...

  7. classList

    1,classList.remove(value) // 删除value项 2, classList.contains(value) // 判断列表中是否存在给定的值,存在返回true,否则返回fal ...

  8. python开发_tkinter_修改tkinter窗口的红色图标'Tk'

    学过java的swing可能知道,在创建一个窗口的时候,窗口的左上角是一个咖啡图标 如下图所示: 在python中,tkinter模块生成的窗口左上角是一个:Tk字样的图标(Tk为tkinter的缩写 ...

  9. The YubiKey NEO

    The YubiKey NEO The YubiKey line of hardware one-time-password (OTP) generators has been on the mark ...

  10. window api 监控

    http://pnig0s1992.blog.51cto.com/393390/704189