一,效果图。

二,工程图。

三,代码。

RootViewController.h

  1. #import <UIKit/UIKit.h>
  2.  
  3. @interface RootViewController : UIViewController
  4. <UITableViewDataSource,UITableViewDelegate>
  5. {
  6. NSArray * dataArray;
  7. NSArray * aboutArray;
  8. }
  9.  
  10. @end

RootViewController.m

  1. #import "RootViewController.h"
  2.  
  3. @interface RootViewController ()
  4.  
  5. @end
  6.  
  7. @implementation RootViewController
  8.  
  9. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  10. {
  11. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  12. if (self) {
  13. // Custom initialization
  14. }
  15. return self;
  16. }
  17.  
  18. - (void)viewDidLoad
  19. {
  20. [super viewDidLoad];
  21. // Do any additional setup after loading the view.
  22.  
  23. self.title=@"tableViewOfTwoSection";
  24. //初始化背景图
  25. [self initBackGroundView];
  26. //初始化数据
  27. [self initData];
  28. }
  29. #pragma -mark -funcitons
  30. -(void)initBackGroundView
  31. {
  32. UITableView * tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 376) style:UITableViewStyleGrouped];
  33. tableview.delegate = self;
  34. tableview.dataSource = self;
  35. [self.view addSubview:tableview];
  36.  
  37. }
  38. -(void)initData
  39. {
  40. dataArray = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:@"脑筋急转弯", @"title", nil],[NSDictionary dictionaryWithObjectsAndKeys:@"儿童饮食", @"title", nil], [NSDictionary dictionaryWithObjectsAndKeys:@"儿童健康", @"title", nil],[NSDictionary dictionaryWithObjectsAndKeys:@"宝宝资讯", @"title", nil],nil];
  41.  
  42. aboutArray = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:@"关于", @"title", @"aboutViewController", @"class", nil], nil];
  43. }
  44. #pragma -mark -UITableViewDelegate
  45. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  46. {
  47. return 2;
  48.  
  49. }
  50. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  51. {
  52. if(section==0)
  53. {
  54. return dataArray.count;
  55. }
  56. else if(section==1)
  57. {
  58.  
  59. return aboutArray.count;
  60. }
  61. return 0;
  62. }
  63.  
  64. -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  65. {
  66. UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"ID"];
  67. if(cell==nil)
  68. {
  69. cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"ID"];
  70.  
  71. }
  72. if(indexPath.section==0){
  73. cell.textLabel.text =[[dataArray objectAtIndex:indexPath.row]objectForKey:@"title"];
  74. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  75. }else if(indexPath.section==1)
  76. {
  77. cell.textLabel.text = [[aboutArray objectAtIndex:indexPath.row]objectForKey:@"title"];
  78. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  79. }
  80. return cell;
  81. }
  82. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  83. {
  84. if(indexPath.section==0)
  85. {
  86. if(indexPath.row==0)
  87. {
  88. NSLog(@"脑筋急转弯");
  89. }else if (indexPath.row==1){
  90. NSLog(@"儿童饮食");
  91. }else if (indexPath.row==2){
  92. NSLog(@"儿童健康");
  93. }else if (indexPath.row==3){
  94. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://baby.163.com"]];
  95. }
  96.  
  97. }else if (indexPath.section==1) {
  98. if(indexPath.row==0)
  99. {
  100. NSLog(@"关于");
  101. }
  102. }
  103. }
  104.  
  105. - (void)didReceiveMemoryWarning
  106. {
  107. [super didReceiveMemoryWarning];
  108. // Dispose of any resources that can be recreated.
  109. }
  110.  
  111. @end

【代码笔记】iOS-TableViewOfTwoSecton的更多相关文章

  1. IOS开发笔记 IOS如何访问通讯录

    IOS开发笔记  IOS如何访问通讯录 其实我是反对这类的需求,你说你读我的隐私,我肯定不愿意的. 幸好ios6.0 以后给了个权限控制.当打开app的时候你可以选择拒绝. 实现方法: [plain] ...

  2. 【hadoop代码笔记】Mapreduce shuffle过程之Map输出过程

    一.概要描述 shuffle是MapReduce的一个核心过程,因此没有在前面的MapReduce作业提交的过程中描述,而是单独拿出来比较详细的描述. 根据官方的流程图示如下: 本篇文章中只是想尝试从 ...

  3. 【hadoop代码笔记】hadoop作业提交之汇总

    一.概述 在本篇博文中,试图通过代码了解hadoop job执行的整个流程.即用户提交的mapreduce的jar文件.输入提交到hadoop的集群,并在集群中运行.重点在代码的角度描述整个流程,有些 ...

  4. 【Hadoop代码笔记】目录

    整理09年时候做的Hadoop的代码笔记. 开始. [Hadoop代码笔记]Hadoop作业提交之客户端作业提交 [Hadoop代码笔记]通过JobClient对Jobtracker的调用看详细了解H ...

  5. 笔记-iOS 视图控制器转场详解(上)

    这是一篇长文,详细讲解了视图控制器转场的方方面面,配有详细的示意图和代码,为了使得文章在微信公众号中易于阅读,seedante 辛苦将大量长篇代码用截图的方式呈现,另外作者也在 Github 上附上了 ...

  6. <Python Text Processing with NLTK 2.0 Cookbook>代码笔记

    如下是<Python Text Processing with NLTK 2.0 Cookbook>一书部分章节的代码笔记. Tokenizing text into sentences ...

  7. [学习笔记] SSD代码笔记 + EifficientNet backbone 练习

    SSD代码笔记 + EifficientNet backbone 练习 ssd代码完全ok了,然后用最近性能和速度都非常牛的Eifficient Net做backbone设计了自己的TinySSD网络 ...

  8. DW网页代码笔记

    DW网页代码笔记 1.样式.       class  插入类样式  标签技术(html)解决页面的内容样式技术(css)解决页面的外观脚本技术       解决页面动态交互问题<form> ...

  9. 前端学习:JS(面向对象)代码笔记

    前端学习:JS(面向对象)代码笔记 前端学习:JS面向对象知识学习(图解) 创建类和对象 创建对象方式1调用Object函数 <body> </body> <script ...

  10. 离屏渲染学习笔记 /iOS圆角性能问题

    离屏渲染学习笔记 一.概念理解 OpenGL中,GPU屏幕渲染有以下两种方式: On-Screen Rendering 意为当前屏幕渲染,指的是GPU的渲染操作是在当前用于显示的屏幕缓冲区中进行. O ...

随机推荐

  1. Liferay7 BPM门户开发之2: BPMN 2.0 规范入门 (Activiti BPMN extensions)

    Liferay最大的问题是BPM弱,如果做企业开发,BPM必不可少,所以直入主题,做个BPMN2入门. 本文参考地址:http://activiti.org/userguide/index.html# ...

  2. MongoDB作为windows服务来安装

    首先区官网下载对应版本的安装文件,我本地的环境是win7 bit64 我下载的版本是:mongodb-win32-x86_64-2.4.6 ok, 文件下载后,开始安装,这里要说一下,如果直接启动Mo ...

  3. 解析BroadcastReceiver之你需要了解的一些东东

    前些天把四大组件之一的Service扯了一遍,今天就要开始谈谈它的弟兄BroadcastReceiver了.写到这里我挺纠结的,因为广播接收者确实比较简单,但是各位就不要以为简单的就不内涵,也许我们慢 ...

  4. eclipse maven jdk全局设置

    <profile> <id>jdk-1.8</id> <activation> <activeByDefault>true</acti ...

  5. 【原】ATI显卡设置双显示器

    Ubuntu 12.04系统下加上增加一个显示器后,一直只能镜像显示,或只能用笔记本的屏幕显示,另一个屏幕无法使用了,上网搜索了一下解决办法,通过下面的方法可以解决问题: 编辑/etc/X11/xor ...

  6. C语言使用hiredis访问redis

    Hiredis 是Redis数据库的简约C客户端库.它是简约的,因为它只是增加了对协议的最小支持,但是同时它使用了一个高级别的 printf-like API,所以对于习惯了 printf 风格的C编 ...

  7. Spring mvc 4系列教程(二)——依赖管理(Dependency Management)和命名规范(Naming Conventions)

    依赖管理(Dependency Management)和命名规范(Naming Conventions) 依赖管理和依赖注入(dependency injection)是有区别的.为了将Spring的 ...

  8. springboot-29-security(二)用户角色权限控制

    本博客基于上一个http://www.cnblogs.com/wenbronk/p/7379865.html 增加了角色的权限表, 可以进行权限校验 一, 数据准备 1, 数据表建立 /* Navic ...

  9. php的explode()和implode()方法

    php 中,字符串与数组互转       拆分字符串 到数组 explode()    - -(其他语言中的 split) 将数组连接成字符串 implode() <?php $test = ' ...

  10. JVM内存结构(转)

    所有的Java开发人员可能会遇到这样的困惑?我该为堆内存设置多大空间呢?OutOfMemoryError的异常到底涉及到运行时数据的哪块区域?该怎么解决呢?其实如果你经常解决服务器性能问题,那么这些问 ...