//
// PopularizaOfScience.m
// Patient
//
// Created by y on 15/11/4.
// Copyright © 2015年 ShangYu. All rights reserved.
//
#import "PopularizaOfScience.h"
#import "polularScienceArticleDetails.h"
#import "CustomFlowLayout.h"
//#define WIDTHCOLLECTION (SCREEN_WIDTH-18-15)/4
@interface PopularizaOfScience ()<UITableViewDataSource,UITableViewDelegate,UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
{
int number;
UIImageView *imagershuju;
UILabel *tiwuxianLab;
UICollectionView *_collectionView;
NSMutableArray *selectM;
UILabel *labelFontColor;
UIImageView *imageBim ;
NSMutableArray *tabMut;
NSMutableArray *signMut;
NSString *signStr;
BOOL isRequest;
NSInteger jiuNum ;
NSMutableArray *namesArr;
NSString *totalPage;
//gzz0614 yangzhuang
int pageNumber;
int page; //就是那个 number
int tempPage;
int yz;
//gzz0802
NSIndexPath *preIndexpath;
BOOL isOneTag;//gzz0822
NSIndexPath *zeroIndexpath;
UIView *lineview;
}
@property (nonatomic,strong) UITableView *PopulaTableview;
@property (nonatomic,strong) NSMutableArray *GardenPlotArray;
@property(nonatomic,strong)NSMutableArray *tempArray;//yang
@end
@implementation PopularizaOfScience
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self POScrienceRequest];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"科普园地";
self.view.backgroundColor=[UIColor whiteColor];
number=1;
isOneTag = YES;
tempPage = 1;
_GardenPlotArray = [NSMutableArray array];
_tempArray = [[NSMutableArray alloc]init];
selectM = [NSMutableArray array];
namesArr = [NSMutableArray array];
jiuNum = 0 ;
signStr = @"";
tabMut = [NSMutableArray array];
signMut = [NSMutableArray array];
UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"NavBack"] originalImage] style:UIBarButtonItemStylePlain target:self action:@selector(backClick)];
self.navigationItem.leftBarButtonItem=backItem;
self.navigationController.interactivePopGestureRecognizer.delegate = nil;
UIImageView *imageBim1 = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"jianbian5"]];
imageBim1.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
imageBim = imageBim1;
[self.view addSubview:imageBim1];
[self SignalUI];
[self signRequest];
[self Popuofview];
}
//下拉刷新
- (void)Downrefresh
{
__weak PopularizaOfScience *puad = self;
[puad.PopulaTableview addHeaderWithCallback:^{
[puad.GardenPlotArray removeAllObjects];
number=1;
[puad POScrienceRequest];
[puad.PopulaTableview headerEndRefreshing];
}];
}
//上拉加载
- (void)haderwith
{
__weak PopularizaOfScience *pudb = self;
[pudb.PopulaTableview addFooterWithCallback:^{
number++;
tempPage = number + 2;
[pudb POScrienceRequest];
[pudb.PopulaTableview footerEndRefreshing];
}];
}
#pragma mark UI界面
- (void)Popuofview
{
self.PopulaTableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 64+40, SCREEN_WIDTH, SCREEN_HEIGHT-40-64)];
_PopulaTableview.showsVerticalScrollIndicator = YES;
_PopulaTableview.backgroundColor = [UIColor whiteColor] ;
self.PopulaTableview.delegate = self;
self.PopulaTableview.dataSource = self;
_PopulaTableview.tableFooterView=[[UIView alloc]init];
[self.view addSubview:self.PopulaTableview];
imagershuju = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2-ImagerWuWidth/2, SCREEN_HEIGHT/2-ImagerWuheight/2, ImagerWuWidth, ImagerWuheight)];
imagershuju.image = [UIImage imageNamed:@"zanwushuju1"];
imagershuju.hidden = YES;
[self.view addSubview:imagershuju];
tiwuxianLab = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2-TishiLabwidth/2, CGRectGetMaxY(imagershuju.frame), TishiLabwidth, 30)];
tiwuxianLab.text = @"暂无科普文章";
tiwuxianLab.textAlignment = YES;
tiwuxianLab.textColor = RGB(204, 204, 204);//RGB(188, 188, 188);
tiwuxianLab.hidden = YES;
tiwuxianLab.font = SYSTEMFONT(TishiLabFont);
[self.view addSubview:tiwuxianLab];
[self haderwith];
[self Downrefresh];
}
-(void)SignalUI{
CustomFlowLayout *flowLayOut = [[CustomFlowLayout alloc]init];
flowLayOut.sectionInset = UIEdgeInsetsMake(11, 20, 11, 20);
flowLayOut.scrollDirection = UICollectionViewScrollDirectionHorizontal;
_collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 64, SCREENW, 40) collectionViewLayout:flowLayOut];
flowLayOut.minimumInteritemSpacing = 20;//最小值间隔gzz0920
flowLayOut.maximumInteritemSpacing = 20;//最大间隔
_collectionView.scrollEnabled = YES;
_collectionView.showsHorizontalScrollIndicator = NO;
_collectionView.showsVerticalScrollIndicator = NO;
_collectionView.dataSource = self;
_collectionView.delegate = self;
_collectionView.backgroundColor = WHITECOLORS;//RGB(206, 248, 246);
[self.view addSubview:_collectionView];
[_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cellColling"];
UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_collectionView.frame)-0.5, SCREEN_WIDTH, 0.5)];
line.backgroundColor = RGB(188, 188, 188);//[UIColor ];
lineview = line;
[self.view addSubview:line];
}
#pragma mark 标签请求
-(void)signRequest{
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];//gzz0617af
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"text/plain",@"text/json",@"application/json", nil];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
NSString *Srurl = [NSString stringWithFormat:@"%@polularScienceArticleTabList",Public_URL];
[manager POST: Srurl parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil];
NSString *coder = [NSString stringWithFormat:@"%@",dic[@"code"]];
if ([coder isEqualToString:@"1"]) {
[tabMut addObjectsFromArray:dic[@"data"]];
}
[_collectionView reloadData];//gzz0804
if (tabMut.count>0) {
_collectionView.backgroundColor = WHITECOLORS;//RGB(206, 248, 246);
}else{
_collectionView.backgroundColor = WHITECOLORS;
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[MBProgressHUD hideHUDForView:self.view animated:YES];
_collectionView.backgroundColor = WHITECOLORS;
[self showHint:@"加载数据失败!"];
}];
}
#pragma mark collectview datasource delegate start
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
if (tabMut.count>0) {
return tabMut.count;
}else {
return 0;
}
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"cellColling";
UICollectionViewCell *cell = (UICollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
for (UIView *view in cell.contentView.subviews) {
[view removeFromSuperview];
}
cell.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview:[self cellIndex:(int)indexPath.item]];
NSString *names = [NSString stringWithFormat:@"%@",[[tabMut objectAtIndex:indexPath.item] objectForKey:@"name"]];
for (int i=0; i<namesArr.count; i++) {
if ([namesArr containsObject:names]) {
cell.layer.borderColor = [[UIColor colorWithRed:60/255.0 green:199/255.0 blue:192/255.0 alpha:1] CGColor];
}
}
return cell;
}
-(UIView *)cellIndex:(NSInteger)index{
UIView *viewdd = [[UIView alloc]initWithFrame:CGRectMake(0, 0.8, 100, 18)];
UILabel *labell = [[UILabel alloc]init];
if (tabMut.count>0) {
viewdd.backgroundColor = [UIColor clearColor];
labell.frame = CGRectMake(0,0 , 100, 18);
labell.text = [NSString stringWithFormat:@"%@",[[tabMut objectAtIndex:index] objectForKey:@"name"]];
labell.font = [UIFont systemFontOfSize:16];
[labell sizeToFit];
labell.tag = 4022+index;
labell.textColor = [UIColor grayColor];
labell.textAlignment = NSTextAlignmentCenter;
[viewdd addSubview:labell];
viewdd.frame = CGRectMake(viewdd.x, viewdd.y, labell.width, 18+0.8);
labell.centerY = viewdd.centerY;
labell.centerX = viewdd.centerX;
NSString *names = [NSString stringWithFormat:@"%@",[[tabMut objectAtIndex:index] objectForKey:@"name"]];
for (int i=0; i<namesArr.count; i++) {
if ([namesArr containsObject:names]) {
labell.textColor = [UIColor colorWithRed:60/255.0 green:199/255.0 blue:192/255.0 alpha:1];
}
}
}
return viewdd;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
if(tabMut.count>0){
UILabel *labelW = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 18)];
labelW.text = [[tabMut objectAtIndex:indexPath.item] objectForKey:@"name"];
labelW.font = [UIFont systemFontOfSize:16];
[labelW sizeToFit];
return CGSizeMake(labelW.width, 18);
}else{
return CGSizeMake(0, 0);
}
}
///距边界缩放大小
//-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
//{
// return UIEdgeInsetsMake(13, 20, 9,20 );//分别为上、左、下、右6666gzz0920
//}
//UICollectionView被选中时调用的方法gzz0802
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
// UICollectionViewCell *cell = (UICollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];gzz0919w
NSString *selectItem = [NSString stringWithFormat:@"select%zd",indexPath.item];
if (![selectM containsObject:selectItem]) {
[selectM removeAllObjects];
[signMut removeAllObjects];
[namesArr removeAllObjects];
[selectM addObject:selectItem];
// cell.layer.cornerRadius = 12;
// cell.layer.masksToBounds = YES;
// cell.layer.borderWidth = 1;
// cell.layer.borderColor = [[UIColor colorWithRed:60/255.0 green:199/255.0 blue:192/255.0 alpha:1] CGColor];
UILabel * lab = (UILabel *)[self.view viewWithTag:4022+indexPath.item];
lab.textColor = [UIColor colorWithRed:60/255.0 green:199/255.0 blue:192/255.0 alpha:1];
if (preIndexpath && preIndexpath != indexPath) {
// UICollectionViewCell *cell = (UICollectionViewCell *)[collectionView cellForItemAtIndexPath:preIndexpath];//gzz0919w
UILabel * lab = (UILabel *)[self.view viewWithTag:4022+preIndexpath.item];
lab.textColor = [UIColor grayColor];
}
NSString *signS = [NSString stringWithFormat:@"%@",[[tabMut objectAtIndex:indexPath.item] objectForKey:@"id"]];
[signMut addObject:signS];
//增加一个名字gzz0515
NSString *names = [NSString stringWithFormat:@"%@",[[tabMut objectAtIndex:indexPath.item] objectForKey:@"name"]];
[namesArr addObject:names];
signStr = [signMut componentsJoinedByString:@","];
number = 1;
_GardenPlotArray = [NSMutableArray array];
[self POScrienceRequest];
MCLog(@"选==%@, 现有=%@,传递数据 ===%@",signS,signMut,signStr);
}else{
NSString *signS = [NSString stringWithFormat:@"%@",[[tabMut objectAtIndex:indexPath.item] objectForKey:@"id"]];
[signMut removeObject:signS];
NSString *names = [NSString stringWithFormat:@"%@",[[tabMut objectAtIndex:indexPath.item] objectForKey:@"name"]];
[namesArr removeObject:names];
signStr = [signMut componentsJoinedByString:@","];
MCLog(@"去掉了==%@,还剩下=%@,传递 ===%@",signS,signMut,signStr);
number = 1;
_GardenPlotArray = [NSMutableArray array];
[self POScrienceRequest];
[selectM removeObject:selectItem];
UILabel * lab = (UILabel *)[self.view viewWithTag:4022+indexPath.item];
lab.textColor = [UIColor grayColor];
}
preIndexpath = indexPath;//gzz0802
}
#pragma mark collect datasource delegate end
#pragma mark 内容请求
- (void) POScrienceRequest
{
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];//gzz0617af
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"text/plain",@"text/json",@"application/json", nil];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
NSString *Srurl = [NSString stringWithFormat:@"%@polularScienceArticleListByTab",Public_URL];//polularScienceArticleTabList
NSMutableDictionary *dicm = [NSMutableDictionary dictionary];
NSString * str ;
if (tempPage>=number) {
str = [NSString stringWithFormat:@"%d",number];
}else{
str = [NSString stringWithFormat:@"%d",tempPage];
}
dicm[@"page"]= str;
dicm[@"type"] = signStr;
[manager POST: Srurl parameters:dicm progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSMutableDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil];
NSString *coder = [NSString stringWithFormat:@"%@",dic[@"code"]];
NSDictionary *dicc =[DicRemove clearErrorData11a:dic];
if ([coder isEqualToString:@"1"]) {
NSArray * arr = [dicc objectForKey:@"data"];
if (number >= 2) {
if (tempPage>number) {
[_GardenPlotArray addObjectsFromArray:arr];//gzz0613
}else{
_tempArray = [[NSMutableArray alloc]init];
[_tempArray addObjectsFromArray:arr];//gzz0613
NSRange range8 = NSMakeRange(10*(tempPage-1), _tempArray.count);
[_GardenPlotArray replaceObjectsInRange:range8 withObjectsFromArray:_tempArray];
}
[_PopulaTableview reloadData];
[MBProgressHUD hideHUDForView:self.view animated:YES];
}
else{
_GardenPlotArray = [[NSMutableArray alloc]init];
if (arr.count>0) {
[_GardenPlotArray removeAllObjects];
[_GardenPlotArray addObjectsFromArray:dicc[@"data"]];//gzz0613
[_PopulaTableview reloadData];
[MBProgressHUD hideHUDForView:self.view animated:YES];
}else{
[_PopulaTableview reloadData];
[MBProgressHUD hideHUDForView:self.view animated:YES];
}
}
}else{
[self showHint:[dicc objectForKey:@"message"]];
}
if (_GardenPlotArray.count>0) {
imagershuju.hidden = YES;
tiwuxianLab.hidden = YES;
_PopulaTableview.backgroundColor = WHITECOLORS;// BG_J_COLOR ;
_collectionView.backgroundColor = WHITECOLORS;//RGB(206, 248, 246);
lineview.hidden = NO;
}else{
imagershuju.hidden = NO;
tiwuxianLab.hidden = NO;
if (tabMut.count <=0) {
lineview.hidden = YES;
}
_collectionView.backgroundColor = WHITECOLORS;
}
[_PopulaTableview reloadData];
[MBProgressHUD hideHUDForView:self.view animated:YES];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[MBProgressHUD hideHUDForView:self.view animated:YES];
if (_GardenPlotArray.count>0) {
imagershuju.hidden = YES;
tiwuxianLab.hidden = YES;
}else{
imagershuju.hidden = NO;
tiwuxianLab.hidden = NO;
lineview.hidden = YES;
}
[MBProgressHUD hideHUDForView:self.view animated:YES];
}];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 80;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (_GardenPlotArray.count>0) {
return _GardenPlotArray.count;
}else{
return 0;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *strint = @"cellKepuGarden";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:strint];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:strint];
}
for (UIView *view in cell.contentView.subviews) {
[view removeFromSuperview];
}
if (_GardenPlotArray.count>0) {
NSDictionary *dic = [DicRemove clearErrorDataZanwu:_GardenPlotArray[indexPath.row]];
UIImageView *imagevview = [[UIImageView alloc]initWithFrame:CGRectMake(10, 6, 102, 68)];
NSString *imagess=[NSString stringWithFormat:@"%@",dic[@"imgPath"]];
NSString *imagename=[NSString stringWithFormat:@"%@%@",ImageUrl,imagess];
[imagevview sd_setImageWithURL:[NSURL URLWithString:imagename] placeholderImage:[UIImage imageNamed:@"contentMren"]];//gzz0919h
[cell.contentView addSubview:imagevview];
UILabel *ttile=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(imagevview.frame)+5,6,SCREEN_WIDTH-25-102,16)];
ttile.text =[dic objectForKey:@"topic"];
ttile.backgroundColor=[UIColor clearColor];
ttile.font=[UIFont systemFontOfSize:16];
[cell.contentView addSubview:ttile];
UILabel* firstLabel = [[UILabel alloc] initWithFrame: CGRectMake(CGRectGetMaxX(imagevview.frame)+5, CGRectGetMaxY(ttile.frame)+5,ttile.width, 28)];
firstLabel.backgroundColor = [UIColor clearColor];
firstLabel.textColor = [UIColor grayColor];
firstLabel.numberOfLines=2;
firstLabel.font = [UIFont systemFontOfSize:14];
[cell.contentView addSubview:firstLabel];
NSString *summary=[NSString stringWithFormat:@"%@",[dic objectForKey:@"summary"]];
NSString *temp;
NSMutableArray *arr=[NSMutableArray array];
int sumIndex=0;
for(int i =0; i < [summary length]; i++)
{
temp = [summary substringWithRange:NSMakeRange(i, 1)];
NSString * regex = @"^[A-Za-z0-9]*$";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
BOOL isMatch = [pred evaluateWithObject:temp];
if (isMatch) {
sumIndex++;
}
[arr addObject:temp];
}
NSArray *arrrr=[self kepuRemoveARRva:@" " arrayy:arr];
summary=[arrrr componentsJoinedByString:@""];
firstLabel.text=summary;
[firstLabel sizeToFit];
UILabel *timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(imagevview.frame)+5, 63, 40, 14)];
timeLabel.backgroundColor = [UIColor clearColor];
timeLabel.textColor = [UIColor grayColor];
timeLabel.font = [UIFont systemFontOfSize:12];
[cell.contentView addSubview:timeLabel];
NSString *timestr=[NSString stringWithFormat:@"%@", [dic objectForKey:@"modifyDate"]];
timestr=[timestr substringToIndex:10];
timeLabel.font=SYSTEMFONT(12);
timeLabel.textAlignment=NSTextAlignmentLeft;
timestr = [timestr substringWithRange:NSMakeRange(5, 5)];
timeLabel.text = timestr;
//总的view
UIView *coverView = [[UIView alloc]init];
coverView.frame = CGRectMake(SCREEN_WIDTH-120-10, 63, 120, 14);
coverView.backgroundColor = [UIColor whiteColor];
coverView.centerY = timeLabel.centerY;
[cell.contentView addSubview:coverView];
#pragma mark 图片+阅读量
UIImageView *readNumImageview = [[UIImageView alloc]init];
readNumImageview.frame = CGRectMake(0, 0, 14, 14);
readNumImageview.image = [UIImage imageNamed:@"read_news"];
[coverView addSubview:readNumImageview];
NSString *readStr=[NSString stringWithFormat:@"%@", [dic objectForKey:@"readnum"]];
NSString *readDa = readStr;
if (readStr.length>=5) {
NSInteger redNum = [readStr integerValue];
NSString *one,*two;
NSInteger onee = redNum/10000;
one = [NSString stringWithFormat:@"%zd",onee];
NSInteger twoo = redNum%10000;
twoo = twoo/1000;
two = [NSString stringWithFormat:@"%zd",twoo];
if (one.length>1) {
readDa=[NSString stringWithFormat:@"%@万",one];
}else{
readDa=[NSString stringWithFormat:@"%@.%@万",one,two];
}
}else{
readDa=[NSString stringWithFormat:@"%@", [dic objectForKey:@"readnum"]];
}
UILabel *readLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(readNumImageview.frame)+5, 0, 32, 14)];
[coverView addSubview:readLabel];
readLabel.backgroundColor = [UIColor clearColor];
readLabel.text = readDa;
readLabel.textAlignment = NSTextAlignmentLeft;
readLabel.textColor = [UIColor grayColor];
readLabel.font = [UIFont systemFontOfSize:12];
readLabel.centerY = readNumImageview.centerY;
#pragma mark 图片+点赞
UIImageView *agreeImageview = [[UIImageView alloc]init];
agreeImageview.frame = CGRectMake(CGRectGetMaxX(readLabel.frame)+5, 0, 14, 14);
agreeImageview.image = [UIImage imageNamed:@"agree_news"];
[coverView addSubview:agreeImageview];
NSString *agreeStr=[NSString stringWithFormat:@"%@", [dic objectForKey:@"agreenum"]];
NSString *agreeDa = agreeStr;
if (agreeDa.length>=5) {
NSInteger redNum = [agreeDa integerValue];
NSString *one,*two;
NSInteger onee = redNum/10000;
one = [NSString stringWithFormat:@"%zd",onee];
NSInteger twoo = redNum%10000;
twoo = twoo/1000;
two = [NSString stringWithFormat:@"%zd",twoo];
if (one.length>1) {
agreeDa=[NSString stringWithFormat:@"%@万",one];
}else{
agreeDa=[NSString stringWithFormat:@"%@.%@万",one,two];
}
}else{
agreeDa=[NSString stringWithFormat:@"%@", [dic objectForKey:@"agreenum"]];
}
UILabel *agreeLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(agreeImageview.frame)+5, 0, 32, 14)];
[coverView addSubview:agreeLabel];
agreeLabel.backgroundColor = [UIColor clearColor];
agreeLabel.text = agreeDa;
agreeLabel.textAlignment = NSTextAlignmentLeft;
agreeLabel.textColor = [UIColor grayColor];
agreeLabel.font = [UIFont systemFontOfSize:12];
agreeLabel.centerY = agreeImageview.centerY;
CGFloat wwww = 14+5+32+5+14+5+32;
coverView.frame = CGRectMake(SCREEN_WIDTH-wwww-10, coverView.y, wwww, 14);
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if (_GardenPlotArray.count>0) {//gzz0909
[self readRequestKe:indexPath.row];
}
}
#pragma mark 点击 阅读量加一的接口
-(void)readRequestKe:(NSInteger)iindex {
yz = (int)iindex/10+1;
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];//gzz0617af
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"text/plain",@"text/json",@"application/json", nil];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
NSString *Strurl = [NSString stringWithFormat:@"%@read",Public_URL];
Dlpontlerexple *dlp =[Dlpontlerexple shareIndence];
NSMutableDictionary *dicer = [NSMutableDictionary dictionary];
dicer[@"type"] =[NSString stringWithFormat:@"%d",2];
dicer[@"user_uuid"] = dlp.uuidstring;
NSDictionary *dicer11dd = [DicRemove clearErrorData11a:[_GardenPlotArray objectAtIndex:iindex]];//gzz0406
dicer[@"news_article_uuid"] = [NSString stringWithFormat:@"%@",dicer11dd[@"uuid"]];
[manager POST: Strurl parameters:dicer progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil];
NSString *codee=[NSString stringWithFormat:@"%@",dic[@"code"]];
if ([codee isEqualToString:@"1"]) {
NSString *isAgree = [NSString stringWithFormat:@"%@",dic[@"isAgree"]];
if (_GardenPlotArray.count>0) {
tempPage = yz;
polularScienceArticleDetails *news=[[polularScienceArticleDetails alloc]init];
NSDictionary *dicer11 = [DicRemove clearErrorData11a:[_GardenPlotArray objectAtIndex:iindex]];
news.PoluDiction = dicer11;
news.kepuUUID = [NSString stringWithFormat:@"%@",dicer11[@"uuid"]] ;
news.kepureadnum =[NSString stringWithFormat:@"%@",dicer11[@"readnum"]] ;
news.kepuAgree = isAgree;
news.kepuAgreenum =[NSString stringWithFormat:@"%@",dicer11[@"agreenum"]] ;
news.hidesBottomBarWhenPushed=YES;
[self.navigationController pushViewController:news animated:YES];
}
}else{
[self showHint:@"新闻详情查询失败!"];
}
[MBProgressHUD hideHUDForView:self.view animated:YES];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[MBProgressHUD hideHUDForView:self.view animated:YES];
[self showHint:@"请求数据失败!"];
}];
}
- (void)backClick
{
[self.navigationController popViewControllerAnimated:YES];
}
#pragma mark 标签的点击请求
-(void)signCommitRequest{
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];//gzz0617af
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"text/plain",@"text/json",@"application/json", nil];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
NSString *Srurl = [NSString stringWithFormat:@"%@polularScienceArticleTabList",Public_URL];//
[manager POST: Srurl parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil];
NSString *coder = [NSString stringWithFormat:@"%@",dic[@"code"]];
if ([coder isEqualToString:@"1"]) {
[tabMut addObjectsFromArray:dic[@"data"]];
}
[MBProgressHUD hideHUDForView:self.view animated:YES];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[MBProgressHUD hideHUDForView:self.view animated:YES];
[self showHint:@"请求数据失败!"];
}];
}
#pragma mark 去掉数组中的值。。。。
-(NSArray *)kepuRemoveARRva:(NSString *)str arrayy:(NSArray *)arr{
//需要去掉的元素数组
NSMutableArray *filteredArray = [[NSMutableArray alloc]initWithObjects:str, nil];
NSPredicate * filterPredicate = [NSPredicate predicateWithFormat:@"NOT (SELF IN %@)",filteredArray];
//过滤数组
NSArray * reslutFilteredArray = [arr filteredArrayUsingPredicate:filterPredicate];
return reslutFilteredArray;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end