//
// 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. solr高亮设置以及摘要

    高亮显示 public SolrDocumentList query(String str) { SolrQuery query = new SolrQuery(str); //设置高亮,以下两种方式 ...

  2. RxJava 操作符 on和doOn 线程切换 调度 Schedulers 线程池 MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  3. 跨平台APP----对Cordova,APPCan,DCloud,APICloud四大平台的分析

    前言: 移动开发是未来一个很重要的IT领域,而跨平台开发将是这一领域最重要的事情.         ----谷震平 一 兵器谱 在国外,最大的是Cordova(PhoneGap,2011年广泛流行), ...

  4. tensorflow项目构建流程

    https://blog.csdn.net/hjimce/article/details/51899683 一.构建路线 个人感觉对于任何一个深度学习库,如mxnet.tensorflow.thean ...

  5. 基于PU-Learning的恶意URL检测

    https://xz.aliyun.com/t/2190 Ya-Lin Zhang, Longfei Li, Jun Zhou, Xiaolong Li, Yujiang Liu, Yuanchao ...

  6. Pearson(皮尔逊)相关系数

    Pearson(皮尔逊)相关系数:也叫pearson积差相关系数.衡量两个连续变量之间的线性相关程度. 当两个变量都是正态连续变量,而且两者之间呈线性关系时,表现这两个变量之间相关程度用积差相关系数, ...

  7. 让你的Python代码更加pythonic

    http://wuzhiwei.net/be_pythonic/ 何为pythonic? pythonic如果翻译成中文的话就是很python.很+名词结构的用法在中国不少,比如:很娘,很国足,很CC ...

  8. CSOM中如何取到managed metadata类型字段的类型信息

    Field.fieldTypeKind返回的是Invalid [解决方法] There is no "Metadata" type of field in the SP.Field ...

  9. NSLayoutConstraint的简单应用

    UIView *topView = [[UIView alloc] init]; topView.backgroundColor = [UIColor redColor]; [self.view ad ...

  10. Wifidog的协议梳理

    上篇文章结合wifidog的协议,讲解了如何实现wifi认证.这篇文章会详细讲解一下wifidog的协议. wifidog的认证流程图 用户连接WIFI会跳转到以下地址: 1 2 3 4 5 6 7 ...