新闻频道下栏目新闻的订阅--小算法

 频道数据

{

    5976 =     (

        "<WJNewsChannelModel: 0x170462400>",

        "<WJNewsChannelModel: 0x170462300>",

        "<WJNewsChannelModel: 0x170462380>",

        "<WJNewsChannelModel: 0x170466180>",

        "<WJNewsChannelModel: 0x170461a00>",

        "<WJNewsChannelModel: 0x170462340>",

        "<WJNewsChannelModel: 0x170462dc0>",

        "<WJNewsChannelModel: 0x170460d00>",

        "<WJNewsChannelModel: 0x170462c80>",

        "<WJNewsChannelModel: 0x170462140>"

    );

    channelIndexKey = 1;

    channelKey = "<WJNewsChannelModel: 0x1742680c0>";

}

    /**取出所有的频道*/

    NSArray *channelDicArr = self.entity.columns;

   [self.httpManager WJgetUserConcernsWithToken:[WJEntity sharedEntity].token dataDic:^(NSDictionary *dataDic) {

 

        /**存储关注栏目的新闻*/

        NSArray *conArray  = dataDic[@"data"];

 

        //存放新闻模型

        [self.dataArray removeAllObjects];

 

        /**订阅频道的索引*/

        NSMutableArray *channelIndexArr = [NSMutableArray array];

        /**订阅栏目的索引*/

        NSMutableArray *columnsInChannle = [NSMutableArray array];

 

 

#pragma mark --- 获取频道,栏目索引

        NSUInteger i=0;

        for( NSDictionary *cDic in channelDicArr ){//遍历频道

            WJNewsChannelModel *cm = cDic[@"channelKey"];

            if( cm && cm.channelId  ){

                /**所有的栏目*/

                NSArray *columns = cDic[cm.channelId];

                /**存储栏目所有的索引*/

                NSMutableArray *columnIndexArr = [NSMutableArray array];

                for( NSDictionary *dic in conArray ){//遍历关注的栏目

                    for(NSUInteger j=0;j<columns.count;j++){//遍历所有的栏目

                        NSString *subscribeColumnID = [NSString objectToString:dic[@"columnId"]];//关注栏目id

                        WJNewsChannelModel *columnItem = columns[j];

                        if([columnItem.channelId isEqualToString:subscribeColumnID]){

                            NSString *columnIndex = [NSString stringWithFormat:@"%ld",j];//存储栏目索引

                            [columnIndexArr addObject:columnIndex];

                        }

                    }

                }

                NSString *channelIndex = cDic[@"channelIndexKey"];//[NSString stringWithFormat:@"%ld",i];//存储频道索引

                if( columnIndexArr && columnIndexArr.count ){

                    [channelIndexArr addObject:channelIndex];

                    //每个频道下有n个栏目数组索引

                    [columnsInChannle addObject:columnIndexArr];

                }

            }

 

            i++;

        }

 

        for(NSUInteger i=0;i<channelIndexArr.count;i++){//遍历频道索引

 

            NSString *cStr = channelIndexArr[i];

            if( [cStr isKindOfClass:[NSString class]] ){

                /**频道索引*/

                NSUInteger channelIndex = cStr.integerValue;//取出每个频道索引

 

                if( columnsInChannle.count > i ){

                        /**从每个频道下取出栏目的数组索引*/

                        NSArray *columnIndexArr = columnsInChannle[i];

 

                        for(NSUInteger j=0;j<columnIndexArr.count;j++){

 

                            NSString *colStr = columnIndexArr[j];

                            if( [colStr isKindOfClass:[NSString class]] ){

                                /**栏目索引*/

                                NSUInteger columIndex = colStr.integerValue;

                                //根据频道获取每条新闻

                                NSArray *dataArray = [WJNewsManager getNewsListWithChannelIndex:channelIndex columnIndex:columIndex page:0];

                                if( dataArray && dataArray.count ){

 

                                    if (![self.dataArray containsObject:[dataArray firstObject]]) {

                                        [self.dataArray addObject:[dataArray firstObject]];

                                    }

                                }

                            }

 

                        }

//                    }

                }

            }

        }

//主线程中更新UI

        dispatch_async(dispatch_get_main_queue(), ^{

 

             [self.tableView reloadData];

        });

 

    }];

 

posted @   TheYouth  阅读(274)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示