uitableview分组的数据2中方式
//
// ViewController.m
// tableviegroup
//
// Created by ganchaobo on 13-7-2.
// Copyright (c) 2013年 ganchaobo. All rights reserved.
// #import "ViewController.h"
#import "Person.h"
@interface ViewController ()
@property(nonatomic,retain)NSMutableArray *mydata;
@end @implementation ViewController #pragma mark -生命周期方法
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UITableView *tableview=[[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
tableview.dataSource=self;
tableview.delegate=self;
[self.view addSubview:tableview];
[tableview release];
self.mydata=[NSMutableArray array];
[self InitData1];
} - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} -(void)viewDidUnload{
[super viewDidUnload];
self.mydata=nil;
} - (void)dealloc
{
self.mydata=nil;
[super dealloc];
}
//数据类--》数组--(包含数组)--(每一个数组中只包含多个字典(并且每个字典只有一个key--value) #pragma mark -初始化数据 -(void)InitData1{
//最外面的数组
for (int i=0; i<2; i++) {
NSMutableArray *arr1=[NSMutableArray array];
for (int j=0; j<3; j++) {
NSString *key=[NSString stringWithFormat:@"itcast-->%zi",j];
NSDictionary *dic=@{key:@(i)};
[arr1 addObject:dic]; }
[self.mydata addObject:arr1];
} } 第一种是字典 //一般数据和控件没有太大直接关系
#pragma mark -uitableview 代理方法
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return self.mydata.count;
} -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
NSArray *sectionq= self.mydata[section];
return sectionq.count;
} -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellIndetify=@"cell";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIndetify];
if(cell==nil){
cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndetify]; }
NSArray *section=self.mydata[indexPath.section];
NSDictionary *row=section[indexPath.row]; cell.textLabel.text=row.allKeys[0] ;
cell.detailTextLabel.text=[NSString stringWithFormat:@"%zi",[row.allValues[0] intValue]];
return cell;
} @end
第二种模型
#import <Foundation/Foundation.h> @interface Person : NSObject
@property(nonatomic,copy)NSString *name;
@property(nonatomic,copy)NSString *dec;
@end //
// ViewController.m
// tableviegroup
//
// Created by ganchaobo on 13-7-2.
// Copyright (c) 2013年 ganchaobo. All rights reserved.
// #import "ViewController.h"
#import "Person.h"
@interface ViewController ()
@property(nonatomic,retain)NSMutableArray *mydata;
@end @implementation ViewController #pragma mark -生命周期方法
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UITableView *tableview=[[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
tableview.dataSource=self;
tableview.delegate=self;
[self.view addSubview:tableview];
[tableview release];
self.mydata=[NSMutableArray array];
[self InitData2];
} - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} -(void)viewDidUnload{
[super viewDidUnload];
self.mydata=nil;
} - (void)dealloc
{
self.mydata=nil;
[super dealloc];
} -(void)InitData2{
//最外面的数组
for (int i=0; i<2; i++) {
NSMutableArray *arr1=[NSMutableArray array];
for (int j=0; j<3; j++) {
Person *ps=[[Person alloc] init];
ps.name=[NSString stringWithFormat:@"itcast-->%zi",j];
ps.dec=[NSString stringWithFormat:@"%zi",j];
[arr1 addObject:ps];
[ps release]; }
[self.mydata addObject:arr1];
} } //一般数据和控件没有太大直接关系
#pragma mark -uitableview 代理方法
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return self.mydata.count;
} -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
NSArray *sectionq= self.mydata[section];
return sectionq.count;
} -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellIndetify=@"cell";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIndetify];
if(cell==nil){
cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndetify]; }
NSArray *section=self.mydata[indexPath.section];
Person *row=section[indexPath.row]; cell.textLabel.text=row.name;
cell.detailTextLabel.text=row.dec;
return cell;
} @end
uitableview分组的数据2中方式的更多相关文章
- IOS第七天(3:UiTableView 模型和数据的分组的显示)
*************UiTableView模型和数据的分组的显示 #import "HMViewController.h" #import "HMHero.h&qu ...
- 浅谈Entity Framework中的数据加载方式
如果你还没有接触过或者根本不了解什么是Entity Framework,那么请看这里http://www.entityframeworktutorial.net/EntityFramework-Arc ...
- Android笔记——Android中数据的存储方式(二)
我们在实际开发中,有的时候需要储存或者备份比较复杂的数据.这些数据的特点是,内容多.结构大,比如短信备份等.我们知道SharedPreferences和Files(文本文件)储存这种数据会非常的没有效 ...
- Android笔记——Android中数据的存储方式(一)
Android中数据的存储方式 对于开发平台来讲,如果对数据的存储有良好的支持,那么对应用程序的开发将会有很大的促进作用. 总体的来讲,数据存储方式有三种:一个是文件,一个是数据库,另一个则是网络.其 ...
- Matlab中数据的存储方式
简介 MATLAB提供了丰富的算法以及一个易于操作的语言,给算法研发工作者提供了很多便利.然而MATLAB在执行某些任务的时候,执行效率偏低,测试较大任务量时可能会引起较长时间的等待.未解决这个问题, ...
- python中json格式数据输出实现方式
python中json格式数据输出实现方式 主要使用json模块,直接导入import json即可. 小例子如下: #coding=UTF-8 import json info={} info[&q ...
- [翻译] C# 8.0 新特性 Redis基本使用及百亿数据量中的使用技巧分享(附视频地址及观看指南) 【由浅至深】redis 实现发布订阅的几种方式 .NET Core开发者的福音之玩转Redis的又一傻瓜式神器推荐
[翻译] C# 8.0 新特性 2018-11-13 17:04 by Rwing, 1179 阅读, 24 评论, 收藏, 编辑 原文: Building C# 8.0[译注:原文主标题如此,但内容 ...
- MySQL数据中分级分组显示数据
前面已经有了SqlServer数据分级分组显示数据了.今天又来做一个MySQL数据库中的分级分组显示,SqlServer中用到了递归,这里为了简单就直接把根的数据显示为0 ,而不用递归了. 在MySQ ...
- 折叠UITableView分组实现方法
做项目的时侯用到了折叠分组,最近就研究了一下,找了一些网上的项目,发现有一些缺点,研究了几天自己终于写出了一个.而且分组的数据源比较灵活,每组之间的状态没有什么影响. 实现的大体思路是每个分组用一个s ...
随机推荐
- 构建配置 ProGuard Shrink 混淆和压缩
官方文档 压缩代码和资源 要尽可能减小 APK 文件,您应该启用压缩来移除 release build 中未使用的代码和资源.此页面介绍如何执行该操作,以及如何指定要在构建时保留或舍弃的代码和资源. ...
- Backbone.js 的 View 中定义事件
使用 Backbone 的 View 时,可以象传统 jQuery 那样定义事件,$("selector").click(function(){...}).幸运的是 Backbon ...
- C++类中的访问权限问题
纠结的东西: private,public,protected方法的访问范围.(public继承下)private: 只能由该类中的函数.其友元函数访问,不能被任何其他访问,该类的对象也不能访问. p ...
- spark0.9分布式安装
http://blog.csdn.net/myboyliu2007/article/details/18990277 spark安装包:spark-0.9.0-incubating-bin-hadoo ...
- 使用矩阵分解(SVD)实现推荐系统
http://ling0322.info/2013/05/07/recommander-system.html 这个学期Web智能与社会计算的大作业就是完成一个推荐系统参加百度电影推荐算法大赛,成绩按 ...
- Git直接拉取远程分支
用Git,一直有个疑惑,可不可以不拉取远程Origin主干,我直接pull一个分支下来 今天想了一下,找到了一个办法 本地分支关联 // 0.新建一个文件夹,然后初始化git git init // ...
- 准备Mahout所用的向量ApplesToVectors
<strong><span style="font-size:18px;">/*** * @author YangXin * @info 准备Mahout所 ...
- IntelliJ IDEA 优化总结
1.修改JVM参数 (IntelliJ IDEA 10.0.1包含以上版本不需要设置) 修改idea.exe.vmoptions配置文件调整以下内容:-Xms256m-Xmx384m-XX:MaxPe ...
- Hadoop2.7.4 在 Windows 10(64位) 详细配置
网上查询资料,实际配置后整理记录. 一.下载安装配置 1.8.0 以上版本 java 环境 完成后,使用 java -version 命令查看是否成功. 二.下载 hadoop-2.7.4.tar.g ...
- 转:nginx模块开发——handler(二)
模块上下文结构 这是一个ngx_http_module_t类型的静态变量.这个变量实际上是提供一组回调函数指针,这些函数有在创建存储配置信息的对象的函数,也有在创建前和创建后会调用的函数.这些函数都将 ...