- 浏览: 516388 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
tangyunliang:
大哥你太历害了谢谢
Android基于XMPP Smack Openfire开发IM【四】初步实现两个客户端通信 -
u013015029:
LZ,请问下,在// 添加消息到聊天窗口 , 这里获取Ed ...
Android基于XMPP Smack Openfire开发IM【四】初步实现两个客户端通信 -
endual:
怎么保持会话,我搞不懂啊
Android基于XMPP Smack Openfire开发IM【一】登录openfire服务器 -
donala_zq:
显示:[2013-11-30 11:50:36 - Andro ...
android-----------新浪微博 -
donala_zq:
哥,运行不了啊
android-----------新浪微博
本次实现的是表视图的分区和索引,代码和前面都差不多,主要还是代理方法的设计实现;
1.新建工程名为Partitation , File->New->Project ->single View Application -> next
[img]
[/img]
2.添加协议和声明变量
#import <UIKit/UIKit.h> @interface PartitionViewController : UIViewController <UITableViewDelegate,UITableViewDataSource> @property (strong,nonatomic) UITableView *partitationTableView; @property (strong,nonatomic) UITableViewCell *partitionTableViewCell; @property (strong,nonatomic) NSDictionary *dicData; @property (strong,nonatomic) NSArray *arrayData; @end
3.添加plist文件,再到ViewDidLoad中初始化视图
plist文件的添加
[img]
[/img]
- (void)viewDidLoad { [super viewDidLoad]; UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]; [self.view addSubview:navBar]; // Do any additional setup after loading the view, typically from a nib. self.partitationTableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStyleGrouped]; self.partitationTableView.delegate=self; self.partitationTableView.dataSource = self; [self.view addSubview:self.partitationTableView]; [self.view addSubview:self.partitationTableView]; // 读取plist文件 NSBundle *bundle = [NSBundle mainBundle]; NSURL *plistURL = [bundle URLForResource:@"partitionInfo" withExtension:@"plist"]; NSDictionary *dictionary = [NSDictionary dictionaryWithContentsOfURL:plistURL]; self.dicData = dictionary; // 读取字典中的key储存数组中 NSArray *array = [self.dicData allKeys]; self.arrayData = array; }
4.实现委托方法
前面我们做的都是return 1,表示返回的是一个分区,现在是从数组中读取字典中的plist文件有几个分区
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return [self.arrayData count]; }
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // 从数组中读取分区的对应的key NSString *stringDataKey = [self.arrayData objectAtIndex:section]; // 根据读取的key从该分区字典中读取数据元素 NSArray *arraySection = [self.dicData objectForKey:stringDataKey]; // 返回的是特定分区的行数 return [arraySection count]; }
根据索引路径获取分区行,需要使用哪个值在从字典中取出来
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSInteger section = [indexPath section]; NSInteger row = [indexPath row]; NSString *key = [self.arrayData objectAtIndex:section]; NSArray *arraySection = [self.dicData objectForKey:key]; static NSString *partitation = @"partitation"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:partitation]; if (cell==nil) { cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:partitation]; } cell.textLabel.text = [arraySection objectAtIndex:row]; return cell; }
给每个分区指定可选标题值
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { NSString *key = [self.arrayData objectAtIndex:section]; return key; }
运行下效果
[img]
[/img]
5.添加索引,当我们查询的东西有几万条向下拖动表视图很显然比较麻烦,添加索引之后可以直接跳到所选的分区
-(NSArray*)sectionIndexTitlesForTableView:(UITableView *)tableView { return self.arrayData; }
运行效果
[img]
[/img]
[img]
[/img]
- PartitionDemo.zip (53.1 KB)
- 下载次数: 1
发表评论
-
新风作浪博客学习(十九)在iOS虚拟键盘上添加动态隐藏按钮
2013-06-08 09:19 815为了给用户比较良好的交付,想在键盘上添加一个按钮,实时根据键盘 ... -
新风作浪博客学习(十八)openURL的使用(iOS调用系统电话、浏览器、地图、邮件等) .
2013-06-08 09:19 932今天遇见一行代码实现打开一个网页,比起印象里的UIWebVie ... -
新风作浪博客学习(十七)UIImageView响应点击事件 .
2013-06-08 09:19 666有时候会遇到点击一张图片,然后让这张图片触发一个事件,或者是跳 ... -
新风作浪博客学习(十六)Navigation + Tab Bar 常用组合框架 .
2013-06-07 08:50 1194看到很多项目中都采用的是Navigation加Tab Bar组 ... -
新风作浪博客学习(十五)google地图定位小Demo .
2013-06-07 08:50 1058[img][/img]今天写的是一个简单功能的google地图 ... -
新风作浪博客学习(十四)怎样向iPhone模拟器中添加图片 .
2013-06-07 08:50 742在我们做项目中可能需要使用图库,模拟器是有图库的,但是如何像其 ... -
新风作浪博客学习(十二)代码实现UITableViewCell表视图单元定制 .
2013-06-07 08:49 932通常情况下我们会希望单元格UITableViewCell显示自 ... -
新风作浪博客学习(十一)UITableViewCell的标记、移动、删除、插入 .
2013-06-06 09:15 1059这篇文章是建立在 代码实现 UITableView与UITa ... -
新风作浪博客学习(十)代码实现 UITableView与UITableViewCell .
2013-06-06 09:14 1113我们常用的表格类视图就是用 UITableView与UITab ... -
新风作浪博客学习(九)两个UIPickerView控件间的数据依赖 .
2013-06-06 09:14 1039本篇实现功能是两个选取器的关联操作,滚动第一个滚轮第二个滚 ... -
新风作浪博客学习(八)代码实现UIPickerView .
2013-06-06 09:14 1241先说一下当个组件选取器,我们创建一个数组NSAray来保存选取 ... -
新风作浪博客学习(七)代码 实现UIDatePicker控件 和 Tab Bar 视图切换 .
2013-06-06 09:15 1074感觉代码写控件都一个理,先在ViewDidLoad中创建控件对 ... -
新风作浪博客学习(六)ios 视图切换翻页效果 .
2013-06-05 11:18 1024本文写的是视图切换,涉及到的内容有 1.实现代码添加Navi ... -
新风作浪博客学习(五)代码实现UISlider 和 UISwitch .
2013-02-18 09:15 1075本次实现的UISlider和UISwi ... -
新风作浪博客学习(四)把plist里数据显示在textField上 .
2013-02-18 09:15 885在代码实现Lable 、textFie ... -
新风作浪博客学习(三)NSBundle读取图片 plist文件和txt文件
2013-02-18 09:15 1625本文想简单介绍一下NSBundle读取图片到视图上,读取pli ... -
新风作浪博客学习(二)代码实现Lable 、textField创建界面以及键盘的处理
2013-02-18 09:15 1137今天写的是用代码实现一个简单界面,代码重复率比较高,可读性不是 ... -
新风作浪博客学习(一)plist文件读写操作
2013-02-18 09:14 1300文件plist 全名Property List,属性列表文件, ... -
GCDiscreetNotificationView提示视图
2013-06-05 11:17 525先看一下效果图: [img] ... -
iphone开发之适配iphone5
2013-06-05 11:15 1010iphone5出来了,从不用适配的我们也要像android一样 ...
相关推荐
iO2开l中那些高效常用的宏新风作浪的博客T栏新风作浪的博客T栏懂得y|O表现yxP才iy|O锋芒yxO很浅薄O一眼就能被看穿. 沉R来O打根tO让d人S会觉得
新风系统任务进度表.xlsx新风系统任务进度表.xlsx新风系统任务进度表.xlsx
新风合同.pdf
新风空气处理机调试记录表.pdf
新风系统设计PPT学习教案.pptx
新风系统简介PPT学习教案.pptx
专业新风系统资料PPT学习教案.pptx
新风机仪表自控系统介绍PPT学习教案.pptx
森德中央新风系统报价表汇编.pdf
学习讲正气树新风心得.doc
学雷锋树新风.docx
基于Springboot的新风图书馆管理系统的设计与实现.docx基于Springboot的新风图书馆管理系统的设计与实现.docx基于Springboot的新风图书馆管理系统的设计与实现.docx基于Springboot的新风图书馆管理系统的设计与实现....
新风机组三种控制方案.doc
新风系统设计重点PPT学习教案.pptx
新风系统的设计PPT学习教案.pptx
商贸零售行业深度分析:医美赛道添新宠,胶原蛋白迎新风.pdf
机房新风系统介绍.pdf
疫情下财务和审计数字化发展新风.pdf
新风机组.bhy