iOS实战开发

iOS-关注功能本地模型数据需要做的逻辑处理

2016-05-31  本文已影响107人  暖游丶

一.当我们请求服务器关注成功后,本地的模型数据也要进行处理,因为服务器是取反Type为0的时候说明关注成功,Type为1的时候请求,则取消关注,(1-0,0-1)

请求关注

//--关注人

-(void)requestFoucsPeople:(NSMutableArray *)array

{

NSString *userID = [UserManager sharedUserManager].user.userid;

NSMutableArray *dataArray = [[NSMutableArray alloc] init];

for (floorModel *model in array) {

NSDictionary *countDic = @{@"id":[NSString stringWithFormat:@"%ld",(long)model.userid]};

[dataArray addObject:countDic];

}

NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dataArray options:NSJSONWritingPrettyPrinted error:nil];

NSString *contras = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];

NSDictionary *parameter =

@{@"userid":userID,@"type":@"0",@"counterpartyid":contras};

[[RequestManager shareManager] requestDataWithRequestType:GetAttend parameters:parameter filePath:@""httpMethod:KHTTPPOST completionHandler:^(ResponseItem *respones) {

NSLog(@"%@",respones.dataDic);

RequestStatus status = [respones.dataDic[KResult] integerValue];

if (status == RequestStatusSuccess) {

[MBProgressHUD showSuccess:@"成功" toView:self.view];

[self.tableViewOne addAllPeopleAttention:nil];

}

else

{

[MBProgressHUD hideHUDForView:self.view animated:YES];

[MBProgressHUD showError:@"请求失败" toView:self.view];

}} failedHandler:^(NSError *error) {

NSLog(@"%@",error.localizedDescription);

[MBProgressHUD hideHUDForView:self.view animated:YES];

[MBProgressHUD showError:@"请求失败" toView:self.view];}];}

二,请求成功后,需要对已经关注的数组进行涮选本地取反从而达到正确的显示本地的关注状态

- (void)addAllPeopleAttention:(NSArray*)array{

floorModel *changeModel;

if(array)

{

changeModel = [array objectAtIndex:0];

}

else

{

changeModel = nil;

}

NSMutableArray *tmpArray = [NSMutableArray arrayWithCapacity:0];

for(int i = 0;i<self.peopleArr.count;i++)

{

floorModel *model1 = self.peopleArr[i];

floorModel *model = [[floorModel alloc]init];

model = model1;

BOOL focus = [model1.focused boolValue];

if(changeModel)

{

if(model1 == changeModel)//关注或取消关注某一个

{

model.focused = [NSNumber numberWithBool:!focus];

}

[tmpArray addObject:model];

}

else

{

if(!focus)

{

focus = !focus;

model.focused = [NSNumber numberWithBool:focus];

}

[tmpArray addObject:model];

}

}

[self.peopleArr removeAllObjects];

self.peopleArr = [NSMutableArray arrayWithArray:tmpArray];

[self reloadData];

}

上一篇下一篇

猜你喜欢

热点阅读