UICollectionView 数据库元素分组 多种section分开显示
第一遍 复杂方法 : 数据库查询一个表中userID 然后进行分类 中间去重 获得ID个数 放到section 中 显示
#pragma mark - 查询不同的ID 各数
- (void)checkIDsWithCount{
RLMRealm * realm = [[RealmConfigurationshared]realm];
// RLMResults * selectIDResults = [[CarVideoInfoObj objectsInRealm:realm where:@"userID !=0"] sortedResultsUsingKeyPath:@"hostID" ascending:NO];
RLMResults * selectIDResults = [[CarVideoInfoObj allObjectsInRealm:realm] sortedResultsUsingKeyPath:@"hostID"ascending:NO];
NSLog(@"selectIDResults is %@",selectIDResults);
NSMutableArray *userID = [NSMutableArrayarray];
allSectionDic = [NSMutableDictionarynew];
for(CarVideoInfoObj * obj in selectIDResults){
NSInteger userId = obj.userID;
NSNumber * key = @(userId);
NSMutableArray * objects = [allSectionDicobjectForKey:key];
if(objects == nil){
objects = [NSMutableArraynew];
[allSectionDicsetObject:objects forKey:key];
}
[objects addObject:obj];
// NSLog(@"objectID==== %ld",(long)userId);
// [userID addObject:@(userId)];
}
NSLog(@"all carVideoInfo object list is %@",allSectionDic);
// 去重查询个数
NSLog(@"%lu",(unsignedlong)allSectionDic.count);
//统计数组相同元素的个数
sectionDic = [[NSMutableDictionaryalloc] init];
set = [NSSetsetWithArray:userID];
for (NSString *setString inset){
//需要去掉的元素数组
NSMutableArray *filteredArray = [[NSMutableArrayalloc]initWithObjects:setString, nil];
NSMutableArray *dataArray = userID;
NSPredicate * filterPredicate = [NSPredicatepredicateWithFormat:@"NOT (SELF IN %@)",filteredArray];
//过滤数组
NSArray * reslutFilteredArray = [dataArray filteredArrayUsingPredicate:filterPredicate];
NSLog(@"Reslut Filtered Array = %@",reslutFilteredArray);
int number = (int)(dataArray.count-reslutFilteredArray.count);
NSLog(@"number :%d",number);
[sectionDicsetObject:[NSStringstringWithFormat:@"%d",number] forKey:setString];
}
NSLog(@"dic is%@", sectionDic);
_userIDdic = [[NSDictionaryalloc]init];
_userIDdic = sectionDic;
NSArray * keys = [_userIDdicallKeys] ;
dicArray =[NSArrayarray];
dicArray = keys;
}
#pragma mark - UICollectionView delegate dataSource
#pragma mark 定义展示的Section的个数
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
// section 个数
returnset.count;
}
#pragma mark 定义展示的UICollectionViewCell的个数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
// sectionDic is{
// 10006 = 14;
// 10003 = 23;
// }
NSString *key = [dicArrayobjectAtIndex:section];
NSString * count = [_userIDdicobjectForKey:key];
return count.integerValue;
// return 2;
// NSLog(@"2222_videoMode%@",self.videoMode);
// NSLog(@"_videoMode.videos count is %lu",(unsigned long)[self.videoMode.carVideoInfoObjArray count]);
// return [self.videoMode.carVideoInfoObjArray count];
}
第二种方法 查询表格 讲userID 设置为字典的key 不进获取到了以userID不同的个数作为 section 而且每个 userI获取了每个userID的数据 为赋值显示 打好了基础 (仍不完善)
#pragma mark - 查询不同的ID 各数
- (void)checkIDsWithCount{
RLMRealm * realm = [[RealmConfigurationshared]realm];
RLMResults * selectIDResults = [[CarVideoInfoObj allObjectsInRealm:realm] sortedResultsUsingKeyPath:@"hostID"ascending:NO];
NSLog(@"selectIDResults is %@",selectIDResults);
allSectionDic = [NSMutableDictionarynew];
for(CarVideoInfoObj * obj in selectIDResults){
NSInteger userId = obj.userID;
NSNumber * key = @(userId);
NSMutableArray * objects = [allSectionDicobjectForKey:key];
if(objects == nil){
objects = [NSMutableArraynew];
[allSectionDicsetObject:objects forKey:key];
}
[objects addObject:obj];
}
NSLog(@"all carVideoInfo object list is %@",allSectionDic);
_userIDdic = [[NSDictionaryalloc]init];
_userIDdic = allSectionDic;
NSArray * keys = [_userIDdicallKeys] ;
dicArray =[NSArrayarray];
dicArray = keys;
}
#pragma mark - UICollectionView delegate dataSource
#pragma mark 定义展示的Section的个数
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
// section 个数
returnallSectionDic.count;
}
#pragma mark 定义展示的UICollectionViewCell的个数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
NSString *key = [dicArrayobjectAtIndex:section];
// NSString * count = [_userIDdic objectForKey:key];
return [[_userIDdicobjectForKey:key] count];
}
第三种: 完善后的方法 及赋值
UICollectionView 数据库元素分组 多种section分开显示的更多相关文章
- highCharts图表应用-实现多种图表的显示
在数据统计和分析业务中,有时需要在一个图表中将柱状图.饼状图.曲线图的都体现出来,即可以从柱状图中看出具体数据.又能从曲线图中看出变化趋势,还能从饼状图中看出各部分数据比重.highCharts可以轻 ...
- win8.1 win10存储设备和驱动器分开显示
win10同理如下: Windows 8.1不仅将资源管理器重命名为文件管理器,还将用户熟悉的“计算机/我的电脑”改名为“这台电脑”,同时还将原先的布局进行了重构,于是用户最终看到的是这样一个界面: ...
- css隐藏页面元素的多种方法
在平常的样式排版中,我们经常遇到将某个模块隐藏,下面我整理了一下隐藏元素的多种方法以及对比(有的占据空间,有的不占据空间.有的可以点击,有的不能点击.): ( 一 ) display: none; ...
- IE6 IE7 IE8(Q) 负边距 (margin) 导致元素溢出 hasLayout 容器时显示异常
标准参考 根据W3C CSS2.1规范第8.3节中的描述,边距属性设置了一个框的边距区的宽度.'margin' 缩写属性设置所有四边的边距,而其它的边距属性( 'margin-top' ,'margi ...
- 对App数据库元素进行简单的设计
假如对<豆瓣>进行简单的数据库元素设计; 分析页面: 简单的豆瓣一共有以下页面{ 活动页面 活动详情页面 电影页面 电影详情页面 影院页面(一般不用到数据库,不及于数据库考虑) 我的{ 活 ...
- RB1001: IE6 IE7 IE8(Q) 负边距 (margin) 导致元素溢出 hasLayout 容器时显示异常
标准参考 根据W3C CSS2.1规范第8.3节中的描述,边距属性设置了一个框的边距区的宽度.'margin' 缩写属性设置所有四边的边距,而其它的边距属性( 'margin-top' ,'margi ...
- Atitit 数据库排除某一列 字段 显示
Atitit 数据库排除某一列 字段 显示 GROUP_CONCAT 行列转换 mysql利用group_concat()合并多行数据到一行_Mysql_脚本之家 sELECT GROUP_CO ...
- 【css】绝对定位的元素在 ie6 下不显示
问题描述: 在 ie6 中如果一个浮动元素与绝对定位元素相邻的话,在某些情况下绝对定位元素将会消失. 产生原因: 只有当绝对定位元素的邻近浮动元素的宽度大于父层宽度减 3 时(即如果父层宽度是 300 ...
- ios8 UITableView section不显示
ios8 如果UITableView只设置viewForHeaderInSection,则可能section不能显示,iOS7及以下版本显示正常. 解决方案: 设置heightForHeaderInS ...
随机推荐
- 4.9版本的linux内核中实时时钟芯片pcf85263的驱动源码在哪里
答:drivers/rtc/rtc-pcf85263.c,内核配置选项为 CONFIG_RTC_DRV_PCF85263 Location: -> Device Drivers -> Re ...
- Ubuntu 设置为固定ip
vmware设置为桥接模式 使用root登陆ubuntu 使用gedit打开/etc/network/interfaces auto lo iface lo inet loopback auto en ...
- linux top 各个标识的含义 详解
top之前一直都是一知半解,今天周末加班,我的工作已经完成,在等同事吃饭,就把这个写下来. 第一行: top - 20:42:47 up 57 days, 1:25, 4 users, ...
- 【bzoj2333 & luoguP3273】棘手的操作(线段树合并)
题目传送门:bzoj2333 luoguP3273 这操作还真“棘手”..听说这题是可并堆题?然而我不会可并堆.于是我就写了线段数合并,然后调了一晚上,数据结构毁一生!!!QAQ…… 其实这题也可以把 ...
- 关于vuex与v-route的结合使用
把vue实际用于项目的过程中遇到过一些问题 1.如何将vuex和vue-route结合使用(接口调用成功回调页面这类等等) 1.初始考虑的方法是在vuex引入vue-router,vuex写一些业务逻 ...
- Linux内核、 TCP/IP、Socket参数调优
/proc/sys/net目录 所有的TCP/IP参数都位于/proc/sys/net目录下(请注意,对/proc/sys/net目录下内容的修改都是临时的,任何修改在系统重启后都会丢失),例如下面这 ...
- CentOS7下Firewall常用命令
安装它,只需 yum install firewalld 如果需要图形界面的话,则再安装 yum install firewall-config 一.介绍 防火墙守护 firewalld 服务引入了一 ...
- 使用bootstrap时碰到问题$(...).modal is not a function
我出现这个问题是,因为bootstrap没有正确引入. 除了bootstrap的路径需要被正确引入外,它引入时还要放在jquery.js后面,否则也会报这个错误.
- win32调用系统颜色对话框
参考网站:http://blog.csdn.net/u013242177/article/details/50437358 首先要包含commdlg.h头文件,这个是通用对话框的头文件,包括文件对话框 ...
- RabbitMQ消息队列(九)RPC开始应用吧
一 简单应用 RPC——远程过程调用,通过网络调用运行在另一台计算机上的程序的函数\方法,是构建分布式程序的一种方式.RabbitMQ是一个消息队列系统,可以在程序之间收发消息.利用RabbitMQ可 ...