// 树形结构导航模式

/*

树形结构导航模式也是非常重要的导航模式,它将导航视图控制器(UINavigationController)与表视图(UITableView)结合使用,主要用于构建有从属关系的导航。这种导航模式采用分层组织信息的方式,可以帮助我们构建ios效率型应用程序

*/

代码实现如下:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];self.window.backgroundColor = [UIColor grayColor];[self.window makeKeyAndVisible];KFViewController *viewCtl = [[KFViewController alloc] init];self.navigationController = [[UINavigationController alloc] initWithRootViewController:viewCtl];self.window.rootViewController = self.navigationController;[self.navigationController release];[viewCtl release];return YES;// 树形结构导航/*树形结构导航模型中,有两个根视图控制器:一个是应用程序的根视图控制器,它是UINavigationController的实例,通过self.window.rootViewController属性指定。另一个是导航控制器根视图控制器,它一般是UIViewController的实例,通过UINavigationController的构造方法initWithRootViewController:指定,用于提供和呈现导航控制器的一级视图,即我们看到的第一个界面。*/
}
- (void)viewDidLoad
{[super viewDidLoad];self.view.backgroundColor = [UIColor grayColor];mutArr = [[NSMutableArray alloc] initWithCapacity:20];for (int i = 0 ; i < 10 ; i ++){NSString *str = [NSString stringWithFormat:@"苹果_%d",i];[mutArr addObject:str];}// 导航栏标题self.title = @"苹果";// 导航栏左边和右边按钮UIBarButtonItem *navLeftItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(editClick:)];UIBarButtonItem *navRightItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneClick:)];self.navigationItem.leftBarButtonItem = navLeftItem;self.navigationItem.rightBarButtonItem = navRightItem;[navLeftItem release];[navRightItem release];[self initTableView];
}#pragma mark - 初始化UITableView
- (void)initTableView
{m_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 416)];  // 568m_tableView.backgroundColor = [UIColor whiteColor];m_tableView.delegate = self;m_tableView.dataSource = self;[self.view addSubview:m_tableView];[m_tableView release];
}#pragma mark - UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{return 1;
}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{return [mutArr count];
}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{static NSString *indentifier = @"myCell";UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:indentifier];if (cell == nil){cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indentifier] autorelease];}NSString *str = [mutArr objectAtIndex:[indexPath row]];cell.textLabel.text = str;cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;return cell;
}- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{int iRow  = [indexPath row];NSString *str = [mutArr objectAtIndex:iRow];DetailViewController *detailViewCtl = [[DetailViewController alloc] init];detailViewCtl.m_Title = str;[self.navigationController pushViewController:detailViewCtl animated:YES];[detailViewCtl release];
}- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{if (!tableView.editing)return UITableViewCellEditingStyleNone;else {return UITableViewCellEditingStyleDelete;}
}- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{int iRow = [indexPath row];[mutArr removeObjectAtIndex:iRow];[tableView reloadData];
}- (void)editClick:(id)sender
{m_tableView.editing = !m_tableView.editing;
}- (void)doneClick:(id)sender
{m_tableView.editing = NO;
}
//
// DetailViewController.h
//
#import <UIKit/UIKit.h>@interface DetailViewController : UIViewController <UIWebViewDelegate>@property (copy, nonatomic) NSString *m_Title;@end
//
// DetailViewController.m
//
#import "DetailViewController.h"@interface DetailViewController ()@end@implementation DetailViewController- (void)dealloc
{[self.m_Title release];[super dealloc];
}- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];if (self){// Custom initialization}return self;
}- (void)viewDidLoad
{[super viewDidLoad];self.title = self.m_Title;[self intiUI];
}- (void)intiUI
{UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 416)];  // 568webView.backgroundColor = [UIColor clearColor];webView.delegate = self;[self.view addSubview:webView];[webView release];NSString *str = @"http://www.baidu.com";NSURL *url = [NSURL URLWithString:str];NSURLRequest *request = [NSURLRequest requestWithURL:url];[webView loadRequest:request];
}- (void)webViewDidFinishLoad:(UIWebView *)webView
{NSLog(@"finish");
}- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{NSLog(@"%@",[error description]);
}- (void)didReceiveMemoryWarning
{[super didReceiveMemoryWarning];
}@end

至此,树形结构导航介绍已经完毕,程序运行效果图如下:

ios 6效果图:

      

ios 7效果图:

      

ios-使用树形结构导航模式相关推荐

  1. 组合模式Composite——树形结构不再头疼

    组合模式可以在需要针对"树形结构"进行操作的应用中使用,例如扫描文件夹.渲染网站导航结构等等. 一.什么是组合模式? 组合模式将一组相似的对象看做一个对象处理,并根据一个树状结构来 ...

  2. 树形结构的处理——组合模式(二)

    11.2 组合模式概述 对于树形结构,当容器对象(如文件夹)的某一个方法被调用时,将遍历整个树形结构,寻找也包含这个方法的成员对象(可以是容器对象,也可以是叶子对象)并调用执行,牵一而动百,其中使用了 ...

  3. 树形结构的处理——组合模式(五)

    11.5 公司组织结构 在学习和使用组合模式时,Sunny软件公司开发人员发现树形结构其实随处可见,例如Sunny公司的组织结构就是"一棵标准的树",如图11-8所示: 图11-8 ...

  4. 树形结构的处理——组合模式(三)

    11.3  完整解决方案 为了让系统具有更好的灵活性和可扩展性,客户端可以一致地对待文件和文件夹,Sunny公司开发人员使用组合模式来进行杀毒软件的框架设计,其基本结构如图11-5所示: 图11-5  ...

  5. Java设计模式中组合模式是什么/树形结构怎么组合或显示存储,编程怎么实现树形结构

    继续整理记录这段时间来的收获,详细代码可在我的Gitee仓库Java设计模式克隆下载学习使用! 5.7 组合模式 5.7.1 概述 又名整体模式,是用于把一组相似的对象当作一个单一的对象 依据树形结构 ...

  6. 组合模式 -- 树形结构处理

    树形结构在软件中随处可见,例如操作系统中的目录结构.应用软件中的菜单.办公系统中的公司组织结构等等,如何运用面向对象的方式来处理这种树形结构是组合模式需要解决的问题,组合模式通过一种巧妙的设计方案使得 ...

  7. 移动UI设计中的7种主要导航模式

    2019独角兽企业重金招聘Python工程师标准>>> 正如精良的设计一样,优秀的导航也大象无形.不管是浏览好友信息,还是租赁汽车,完美的导航设计能让用户根据直觉使用应用程序,也能让 ...

  8. python 实现结构树模式显示目录下文件

    在发布一个项目或者产品的时候,需要将项目内的文件打包上传,但是下载人员在下载前最好能看到文件包的内容,文件名字等,如果使用手动方式录入就太麻烦了,也容易出错,如果使用文本模式罗列的话看的还不是特别的清 ...

  9. 表格 树形结构 HTML 语言 CSS,HTML介绍(示例代码)

    一.什么是HTML html(hypertext makeup language),中文名为超文本标记语言,他是一门能被浏览器解析成网页的标签语言,当我们使用浏览器访问网页时,那边就有一个服务端给你发 ...

最新文章

  1. jQuery源码分析系列
  2. 利用栈将中缀表达式转化成后缀表达式
  3. C#语言基础——结构体和枚举类型
  4. 每天一道LeetCode-----数组序列,每个元素的值表示最多可以向后跳多远,计算最少跳多少次可以到达末尾
  5. IdentityServer4(六)授权码流程原理之SPA
  6. [Spring5]AOP底层原理
  7. php 查询cpu使用率,php获取CPU使用情况的代码
  8. Android控件之HorizontalScrollView 去掉滚动条
  9. C#调用C++动态库时类型转换
  10. Centos7.4安装Mysql5.6
  11. turtle fillcolor_Python编程:使用海龟turtle画图制作可爱的哆啦A梦,你也可以的。
  12. 基于FPGA ZC706的AD9371ADRV9009网口驱动配置
  13. pycharm一些常用的搜索快捷键
  14. VBS电脑信息检测器
  15. 【飞凌嵌入式 OK3399-C+开发板试用体验】开箱上电
  16. 获取计算机内存镜像文件,Dump镜像内存提取工具
  17. 读书笔记:不可能的技艺,巅峰人生需要凶猛的起点
  18. 中国禁止“外国废物”可能有助于AI在美国的传播
  19. 无人值守安装linux7,PXE下无人值守配置阵列及安装CentOS7
  20. PowerDesigner16.7 安装与配置

热门文章

  1. 换服务器要做网站备案吗,换服务器后域名要重新备案吗
  2. Nutanix的“阳谋”
  3. A站凉了,B站上市,微博曲线入局 破壁的二次元市场成巨头盛宴
  4. 《python游戏开发学习》打飞机小游戏(一)
  5. TVMovie JAVA源代码1.2.4版原生安卓tv源码电视盒子APP开源全前端无后台
  6. 利用开发板上的RS485模块与PC机的串口通讯
  7. 第四次网页前端培训(CSS常用属性与盒子模型)
  8. Hexo部署github博客
  9. java处理时区的注意事项
  10. 10米土地利用数据按行政区下载