新闻频道下栏目新闻的订阅--小算法
频道数据
{
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];
});
}];