一,效果图。

二,工程图。

三,代码。

RootViewController.h

#import <UIKit/UIKit.h>@interface RootViewController : UIViewController
<UITableViewDataSource,UITableViewDelegate>
{NSArray * dataArray; NSArray * aboutArray; } @end

RootViewController.m

#import "RootViewController.h"@interface RootViewController () @end @implementation RootViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization  } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view.  self.title=@"tableViewOfTwoSection"; //初始化背景图  [self initBackGroundView]; //初始化数据  [self initData]; } #pragma -mark -funcitons -(void)initBackGroundView { UITableView * tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 376) style:UITableViewStyleGrouped]; tableview.delegate = self; tableview.dataSource = self; [self.view addSubview:tableview]; } -(void)initData { dataArray = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:@"脑筋急转弯", @"title", nil],[NSDictionary dictionaryWithObjectsAndKeys:@"儿童饮食", @"title", nil], [NSDictionary dictionaryWithObjectsAndKeys:@"儿童健康", @"title", nil],[NSDictionary dictionaryWithObjectsAndKeys:@"宝宝资讯", @"title", nil],nil]; aboutArray = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:@"关于", @"title", @"aboutViewController", @"class", nil], nil]; } #pragma -mark -UITableViewDelegate -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 2; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if(section==0) { return dataArray.count; } else if(section==1) { return aboutArray.count; } return 0; } -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"ID"]; if(cell==nil) { cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"ID"]; } if(indexPath.section==0){ cell.textLabel.text =[[dataArray objectAtIndex:indexPath.row]objectForKey:@"title"]; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; }else if(indexPath.section==1) { cell.textLabel.text = [[aboutArray objectAtIndex:indexPath.row]objectForKey:@"title"]; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; } return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if(indexPath.section==0) { if(indexPath.row==0) { NSLog(@"脑筋急转弯"); }else if (indexPath.row==1){ NSLog(@"儿童饮食"); }else if (indexPath.row==2){ NSLog(@"儿童健康"); }else if (indexPath.row==3){ [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://baby.163.com"]]; } }else if (indexPath.section==1) { if(indexPath.row==0) { NSLog(@"关于"); } } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end

转载于:https://www.cnblogs.com/yang-guang-girl/p/7007189.html

【代码笔记】iOS-TableViewOfTwoSecton相关推荐

  1. CSDN技术主题月----“深度学习”代码笔记专栏

    from: CSDN技术主题月----"深度学习"代码笔记专栏 2016-09-13 nigelyq 技术专题 Hi,各位用户 CSDN技术主题月代码笔记专栏会每月在CODE博客为 ...

  2. 看完师兄的代码笔记,我失眠了

    祝大家中秋节快乐! 最近很多公司的秋季招聘都已经启动了. 想必大家(尤其是经历过求职面试的)都知道,数据结构和算法在求职笔试/面试中的重要性. 纵观如今的互联网公司面试,清一色地都在重点考查这块,不开 ...

  3. LSTM TF核心实现代码笔记

    LSTM TF核心实现代码笔记 1. LSTM TF里的核心代码实现 2. 代码详细讲解 1. LSTM TF里的核心代码实现 LSTM网络的核心实现是在这个包里tensorflow/python.k ...

  4. 2018年最新Spring Boot视频教程附代码笔记资料(50G)

    1. Spring Boot  项目实战 ----- 技术栈博客企业前后端 链接:https://pan.baidu.com/s/1hueViq4 密码:4ma8 2.Spring Boot  项目实 ...

  5. Python Text Processing with NLTK 2.0 Cookbook代码笔记

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

  6. Unity 之 代码获取IOS设备型号 -- 做分辨率适配

    Unity 之 代码获取IOS设备型号 一,通过机器型号校验 1.1 逻辑解释 1.2 实现代码 二,通过长宽比校验 一,通过机器型号校验 1.1 逻辑解释 在https://www.theiphon ...

  7. Transformer课程 第8课NER案例代码笔记-IOB标记

    Transformer课程 第8课NER案例代码笔记-IOB标记 NER Tags and IOB Format 训练集和测试集都是包含餐厅相关文本(主要是评论和查询)的单个文件,其中每个单词都有一个 ...

  8. 2018尚硅谷SpringBoot视频教程附代码+笔记+课件(内含Docker)

    尚硅谷SpringBoot视频教程(内含Docker)附代码+笔记+课件 下载地址:百度网盘

  9. 吴恩达机器学习MATLAB代码笔记(1)梯度下降

    吴恩达机器学习MATLAB代码笔记(1)梯度下降 单变量线性回归 1.标记数据点(Plotting the Date) fprintf('Plotting Data') data = load('D: ...

  10. Transformer课程 第8课NER案例代码笔记-部署简介

    Transformer课程 第8课NER案例代码笔记 BERT微调器 NER是信息提取的子任务,旨在将非结构化文本中提到的命名实体定位并分类为预定义类别,如人名.组织.位置.医疗代码.时间表达式.数量 ...

最新文章

  1. 又见yx — 说说IT公司的团队头儿
  2. 深度学习与计算机视觉(一)图像分类与KNN
  3. suse下删除mysql_每日MySQL之005:SUSE linux下卸載MySQL
  4. java 中batch_java相关:Mybatis中使用updateBatch进行批量更新
  5. 设计模式之单例模式介绍
  6. Hyperledger Fabric 命令整理
  7. 一分钟带你全面了解计算机考研常识,让你对考研不再陌生!
  8. HTML5文档结构语义:页眉的header和hgroup标签使用
  9. 实时数仓入门训练营:Hologres 数据导入/导出实践
  10. 使用单链表统计英文文本单词个数
  11. Kinect传感器的硬件组成
  12. 计算机各盘分配内存,电脑这样分盘,不卡就怪了!
  13. oracle错误号提示ORA-
  14. 基于MRS-Hudi构建数据湖的典型应用场景介绍
  15. 嵌入式远程机房数采监控报警系统
  16. 出门问问发布企业级场景的智能交互屏TicKasa Show,适用于多种场景
  17. cubemx 配置sd卡 读写测试程序
  18. 金融要求计算机水平,什么是金融人才?符合五大标准的金融人
  19. 怎么看电影《穆赫兰道》?
  20. 几十款收费软件现在免费了

热门文章

  1. 8月第4周国内IT网站/频道Top15:太平洋降至第三
  2. TCP/IP 5.3.5 认证
  3. Python库安装相关问题
  4. 银屑病与肠道菌群(调研手稿一)
  5. GraphQL报错:error: NetworkError when attempting to fetch resource.
  6. 什么是单页应用(转)
  7. 指数加权平均与RmsProp(转载+自己总结)以及Adagrad
  8. genymotion无法安装apk的问题
  9. 《On the Momentum Term in Gradient Descent Learning Algorithm》原文解读
  10. Unable to load native-hadoop library for your platform