//
// 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. COCO数据集深入理解

    TensorExpand/TensorExpand/Object detection/Data_interface/MSCOCO/ 深度学习数据集介绍及相互转换 Object segmentation ...

  2. c#以POST方式模拟提交表单

    这是我一年前写的一个用C#模拟以POST方式提交表单的代码,现在记录在下面,以免忘记咯.那时候刚学C#~忽忽..很生疏..代码看上去也很幼稚 臃肿不堪 #region 内容添加函数(Contentin ...

  3. IOS开发之自定义UITabBarController

    UITabBarController是开发中经常会用到的一个视图控制器,但是默认的UITabBarController经常不能够完全满足我们的需求,所以我们经常需要自定义一个UITabBarContr ...

  4. 关于android SDK安装Failed to fetch URL 一点思考

    最近SDK出问题了,然后在google下载了一个android-sdk-windows.rar,然后点击SDK Manager,结果一直不能刷新API Level,然后就开始在网上找了好多资料,解决这 ...

  5. [BUG] Dashboard报错:if usages['subnets']['available'] &lt;= 0: KeyError: 'available'

    Openstack版本号:Liberty 系统平台:CentOS 7.2 64bit ######################################################### ...

  6. 仿qq底部的提示标记

    看到一个比較不错的开源项目,分享给大家: <?xml version="1.0" encoding="utf-8"?> <RelativeLa ...

  7. 设置让php能够以root权限来执行exec() 或者 shell_exec()

    一.查看启动你php的进程的用户是谁. 可以通过在命令行执行:ps -ef | grep php来看.或者在php中执行 echo exec('whoami') 来查看.centos下默认会是nobo ...

  8. CentOS7.1 Liberty云平台之环境准备(2)

    一.各节点配置Openstack源库 yum install centos-release-openstack-liberty -y 升级YUM源库 yum upgrade 安装Openstackcl ...

  9. ASP入门(五)- VBScript过程和函数

    VBScript过程 被封装在Sub和End Sub语句之中的一系列语句 不具有返回值 可带参数 我们的SubFunction.asp中展示了Sub的用法,代码如下: <% Sub mySub( ...

  10. Unity3d 屏幕截图。并保存。iOS

    - ( void ) imageSaved: ( UIImage *) image didFinishSavingWithError:( NSError *)error contextInfo: ( ...