//
// 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中方式的更多相关文章

  1. IOS第七天(3:UiTableView 模型和数据的分组的显示)

    *************UiTableView模型和数据的分组的显示 #import "HMViewController.h" #import "HMHero.h&qu ...

  2. 浅谈Entity Framework中的数据加载方式

    如果你还没有接触过或者根本不了解什么是Entity Framework,那么请看这里http://www.entityframeworktutorial.net/EntityFramework-Arc ...

  3. Android笔记——Android中数据的存储方式(二)

    我们在实际开发中,有的时候需要储存或者备份比较复杂的数据.这些数据的特点是,内容多.结构大,比如短信备份等.我们知道SharedPreferences和Files(文本文件)储存这种数据会非常的没有效 ...

  4. Android笔记——Android中数据的存储方式(一)

    Android中数据的存储方式 对于开发平台来讲,如果对数据的存储有良好的支持,那么对应用程序的开发将会有很大的促进作用. 总体的来讲,数据存储方式有三种:一个是文件,一个是数据库,另一个则是网络.其 ...

  5. Matlab中数据的存储方式

    简介 MATLAB提供了丰富的算法以及一个易于操作的语言,给算法研发工作者提供了很多便利.然而MATLAB在执行某些任务的时候,执行效率偏低,测试较大任务量时可能会引起较长时间的等待.未解决这个问题, ...

  6. python中json格式数据输出实现方式

    python中json格式数据输出实现方式 主要使用json模块,直接导入import json即可. 小例子如下: #coding=UTF-8 import json info={} info[&q ...

  7. [翻译] C# 8.0 新特性 Redis基本使用及百亿数据量中的使用技巧分享(附视频地址及观看指南) 【由浅至深】redis 实现发布订阅的几种方式 .NET Core开发者的福音之玩转Redis的又一傻瓜式神器推荐

    [翻译] C# 8.0 新特性 2018-11-13 17:04 by Rwing, 1179 阅读, 24 评论, 收藏, 编辑 原文: Building C# 8.0[译注:原文主标题如此,但内容 ...

  8. MySQL数据中分级分组显示数据

    前面已经有了SqlServer数据分级分组显示数据了.今天又来做一个MySQL数据库中的分级分组显示,SqlServer中用到了递归,这里为了简单就直接把根的数据显示为0 ,而不用递归了. 在MySQ ...

  9. 折叠UITableView分组实现方法

    做项目的时侯用到了折叠分组,最近就研究了一下,找了一些网上的项目,发现有一些缺点,研究了几天自己终于写出了一个.而且分组的数据源比较灵活,每组之间的状态没有什么影响. 实现的大体思路是每个分组用一个s ...

随机推荐

  1. 关于MAX30100心率的编程

    MAX30100是能够读取心率.血氧的传感器,通信方式是通过IIC进行通信. 其工作原理是通过红外led灯照射,能够得到心率的ADC值. 图为MAX30100的寄存器. 可以分为五类,状态寄存器.FI ...

  2. IIS通过HTML5实现应用程序缓存的离线浏览

    这里我是使用的IIS7: IIS7发布了网站后要想使用HTML5的应用程序缓存,需要增加一个关于文本/缓存清单( text/cache-manifest)的新的MIME类型,选中网站添加一个MIME类 ...

  3. svn“Previous operation has not finished; run 'cleanup' if it was interrupted“报错的解决方法

    今天碰到了个郁闷的问题,svn执行clean up命令时报错“Previous operation has not finished; run 'cleanup' if it was interrup ...

  4. 【Spark】SparkStreaming-输出到Kafka

    SparkStreaming-输出到Kafka sparkstreaming output kafka_百度搜索 SparkStreaming采用直连方式(Direct Approach)获取Kafk ...

  5. Docker-machine创建虚机时停在虚机启动的提示上,并且创建的虚机显示Ip Not found

    Docker-machine创建虚机时停在虚机启动的提示上,并且创建的虚机用docker-machine ls 列出来的时候显示Ip Not found, 是什么原因那? [答案] 看这个帖子: ht ...

  6. 如何检查显卡类型,DirectX和OpenGL的版本

    How To: Check the graphics card type and OpenGL version From: http://support.esri.com/technical-arti ...

  7. Dijkstra和Floyd_warshall

    import java.util.Arrays; import java.util.Scanner; /*题目描写叙述: 有n个城市.城市间有m条道路.每条道路都有长度d.给你起点城市s终点终点t.要 ...

  8. Android通用框架设计与完整电商APP开发系列文章

    作者|傅猿猿 责编|Javen205 有福利 有福利 有福利 鸣谢 感谢@傅猿猿 邀请写此系列文章 Android通用框架设计与完整电商APP开发 课程介绍 [导学视频] [课程详细介绍] 以下是部分 ...

  9. 【Python】使用torrentParser1.02对多文件torrent的分析结果

    C:\Users\horn1\Desktop\python\41-torrentParser>python torrentParser.py 文件名=./6.torrent 文件结构: anno ...

  10. 自然语言处理哪家强?【36kr】

    语音交互事关未来,国内外已经不少公司在抢蛋糕了,大公司收购.投资.合作不断,就可见一斑.目前,基本上所有的巨头都有涉足. 苹果收购 Siri.Novauris,组建基于神经网络算法的语音识别团队 20 ...