第一遍 复杂方法 : 数据库查询一个表中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分开显示的更多相关文章

  1. highCharts图表应用-实现多种图表的显示

    在数据统计和分析业务中,有时需要在一个图表中将柱状图.饼状图.曲线图的都体现出来,即可以从柱状图中看出具体数据.又能从曲线图中看出变化趋势,还能从饼状图中看出各部分数据比重.highCharts可以轻 ...

  2. win8.1 win10存储设备和驱动器分开显示

    win10同理如下: Windows 8.1不仅将资源管理器重命名为文件管理器,还将用户熟悉的“计算机/我的电脑”改名为“这台电脑”,同时还将原先的布局进行了重构,于是用户最终看到的是这样一个界面: ...

  3. css隐藏页面元素的多种方法

    在平常的样式排版中,我们经常遇到将某个模块隐藏,下面我整理了一下隐藏元素的多种方法以及对比(有的占据空间,有的不占据空间.有的可以点击,有的不能点击.): ( 一 )  display:  none; ...

  4. IE6 IE7 IE8(Q) 负边距 (margin) 导致元素溢出 hasLayout 容器时显示异常

    标准参考 根据W3C CSS2.1规范第8.3节中的描述,边距属性设置了一个框的边距区的宽度.'margin' 缩写属性设置所有四边的边距,而其它的边距属性( 'margin-top' ,'margi ...

  5. 对App数据库元素进行简单的设计

    假如对<豆瓣>进行简单的数据库元素设计; 分析页面: 简单的豆瓣一共有以下页面{ 活动页面 活动详情页面 电影页面 电影详情页面 影院页面(一般不用到数据库,不及于数据库考虑) 我的{ 活 ...

  6. RB1001: IE6 IE7 IE8(Q) 负边距 (margin) 导致元素溢出 hasLayout 容器时显示异常

    标准参考 根据W3C CSS2.1规范第8.3节中的描述,边距属性设置了一个框的边距区的宽度.'margin' 缩写属性设置所有四边的边距,而其它的边距属性( 'margin-top' ,'margi ...

  7. Atitit 数据库排除某一列 字段 显示

    Atitit  数据库排除某一列 字段  显示 GROUP_CONCAT  行列转换 mysql利用group_concat()合并多行数据到一行_Mysql_脚本之家 sELECT GROUP_CO ...

  8. 【css】绝对定位的元素在 ie6 下不显示

    问题描述: 在 ie6 中如果一个浮动元素与绝对定位元素相邻的话,在某些情况下绝对定位元素将会消失. 产生原因: 只有当绝对定位元素的邻近浮动元素的宽度大于父层宽度减 3 时(即如果父层宽度是 300 ...

  9. ios8 UITableView section不显示

    ios8 如果UITableView只设置viewForHeaderInSection,则可能section不能显示,iOS7及以下版本显示正常. 解决方案: 设置heightForHeaderInS ...

随机推荐

  1. 【bzoj2734】集合选数(有点思维的状压dp)

    题目传送门:bzoj2734 这题一个月前看的时候没什么头绪.现在一看,其实超简单. 我们对于每个在$ [1,n] $范围内的,没有因数2和3的数$ d $,将它的倍数$ 2^a 3^b d $一起处 ...

  2. MATLAB 图形图像处理

    theme: MATLAB author: pprp date: 2018/2/2 --- MATLAB 图形图像处理 二维绘图命令 plot 线性空间 plot(t,[x1,x2,x3]) : 在同 ...

  3. 从0开始 数据结构 字典树 hdu1251

    字典树 知识补充 '\0'和'\n'的区别 '\0' 是一个字符串的结尾 '\n' 是换行符 gets 和 scanf 的区别 gets()函数总结: gets() 从标准输入设备读取字符串,以回车结 ...

  4. springMvc REST 请求和响应

    前言: 突然怎么也想不起来  springMvc REST 请求的返回  类型了!   (尴尬+究竟)  然后本着 方便的想法 百度了一下 发现了个问题,大家在写      springMvc RES ...

  5. UVa 10883 超级平均数(二项式系数+对数计算)

    https://vjudge.net/problem/UVA-10883 题意: 给出n个数,每相邻两个数求平均数,依次类推,最后得到1个数,求该数. 思路: 演算一下可以发现最后各个数的系数就是二项 ...

  6. grafana二次开发

    grafana官方地址: https://github.com/grafana/grafana 开发文档:http://docs.grafana.org/project/building_from_s ...

  7. Yii框架(一)

    这里接触了 MVC 设计模式中的控制器和视图部分. 创建了一个操作作为控制器的一部分去处理特定请求. 然后又创建了一个视图去构造响应内容. 在这个小例子中,没有模型调用,唯一涉及到数据的地方是 mes ...

  8. Log4j 2.0 使用说明(1) 之HelloWorld

    以下是Log4j2.0的类图,以便大家对2.0有一个整体的理解. 就如我们学习任何一个技术一样,这里我们首先写一个Hello World: 1,新建工程TestLog4j 2,下载Log4j 2.0有 ...

  9. Mysql修改表结构详解

    添加字段: alter table `user_movement_log`Add column GatewayId int not null default 0 AFTER `Regionid` (在 ...

  10. photoshop CS5制作具有立体感的按钮

    今天在学习用photoshop cs5制作html模板的过程中,遇到了立体感按钮的制作问题.当然按钮的立体感也可以用CSS来实现,这里主要是用PS来制作具有立体感的按钮. 我也是PS新手,下面的东西, ...