//
// 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. iOS截屏方法

    //获取屏幕截屏方法 - (UIImage *)capture { // 创建一个context UIGraphicsBeginImageContextWithOptions(self.view.bo ...

  2. iOS开发调试篇—Print Description of "string"

    Print Description of "string":把 string 的信息输出到控制台.Copy:复制 string 的信息,包含变量名,类名和值.View Value ...

  3. window.open不被拦截的实现代码

    $("#last").click(function(){ var w=window.open(); setTimeout(function(){ w.location=" ...

  4. SQL-order by两个字段同时排序

    ORDER BY 后可加2个字段,用英文逗号隔开. --f1用升序, f2降序,sql该这样写 ORDER BY f1, f2 DESC --也可以这样写,更清楚: ORDER BY f1 ASC, ...

  5. windows无法访问vmware搭建好虚拟机linux web服务器

    [前置条件] vmware搭建好虚拟机web服务器 ,但是本机就是无法访问的解决办法. linux虚拟机的网络选择Bridged 桥接到本机网卡. 具体情况如下 : 1.本机能ping通虚拟机 2.虚 ...

  6. 基于ARM的模拟器

    ARM的ARMulator: ARMulator 是一个在 ARM 公司推出的集成开发环境 ADS (ARM Developer Suite)中提供的指令集模拟器.它与运行在通用计算机(通常是x86体 ...

  7. redis清除数据/xargs使用

    redis清除数据/xargs使用 redis比memcache好的地方之一,如果memcache,恐怕就得关掉重启了. 1 使用cli FLUSHDB 清除一个数据库,FLUSHALL清除整个red ...

  8. HTTPS证书撤销

    如果浏览器信息被拦截,可以选择清洗掉之前的证书 关闭浏览器,在CMD中输入命令 certutil -urlcache * certutil -urlcache * delete certutil -u ...

  9. linux 安装elasticsearch 可能遇到的问题

    1.can not run elasticsearch as root 切换到非root用户 因为安全问题elasticsearch 不让用root用户直接运行,所以要创建新用户 第一步:liunx创 ...

  10. IncrediBuild 2.40 过期时间

    IncrediBuild 2.40的License有2个文件CoordLicense.dat和AgentLicense.dat,分别位于Coordinator和Agent安装目录下,这两个文件都是RS ...