2018-01-30-收藏功能

2018/1/30 posted in  工作总结

收藏

  • 项目要求要在首页的视频右下角添加一个收藏的功能
  • 思路:
    • 1. 进入一个界面先要进行判断是否有收藏,所以进行第一次网络请求
    • 2. 判断成功后,在进行第二次事件,用户点击了收藏按钮所做的动作,例如收藏成功、取消收藏
NSString *getiscollect = [QWHttpUrls getiscollectUrl];
NSMutableDictionary *params = [[NSMutableDictionary alloc]init];
[params setValue:[QWAccountModel sharedModel].uid forKey:@"uid"];
[params setValue:@"3" forKey:@"collect_type"];
[params setValue:self.gameID forKey:@"collect_id"];
[QWHttpTool postmanager:getiscollect params:params success:^(id  _Nonnull manager, id  _Nonnull json) {
    QWLog(@"显示collectstatus===%@",json[@"status"]);
    QWLog(@"显示collectURLdata===%@",json[@"data"]);
    if ([json[@"status"] isEqualToString:@"1"]) {
        [self.collectBtn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"已收藏"]] forState:UIControlStateNormal];
//            Isselected = 2;
    }else{
        [self.collectBtn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"收藏"]] forState:UIControlStateNormal];
//            Isselected = 1;
    }
} failure:^(NSError * _Nonnull error) {
    
}];
- (void)btnClick{
    self.collectBtn.selected = !self.collectBtn.selected;
    
    if (Isselected==1) {
        if (self.collectBtn.selected) {
            NSString *collectURL = [QWHttpUrls CollectUrlWithOp:1 withcollect_type:3 Withcollect_id:_movieStr];
            NSMutableDictionary *params = [[NSMutableDictionary alloc]init];
            [params setValue:[QWAccountModel sharedModel].uid forKey:@"uid"];
            [QWHttpTool postmanager:collectURL params:params success:^(id  _Nonnull manager, id  _Nonnull json) {
                QWLog(@"collect结果===%@",json[@"msg"]);
                [QWShowMessage showMessage:[NSString stringWithFormat:@"%@",json[@"msg"]]];
                [self.collectBtn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"已收藏"]] forState:UIControlStateSelected];
            } failure:^(NSError * _Nonnull error) {
                
            }];
        }else{
            NSString *collectURL = [QWHttpUrls CollectUrlWithOp:2 withcollect_type:3 Withcollect_id:_movieStr];
            NSMutableDictionary *params = [[NSMutableDictionary alloc]init];
            [params setValue:[QWAccountModel sharedModel].uid forKey:@"uid"];
            [QWHttpTool postmanager:collectURL params:params success:^(id  _Nonnull manager, id  _Nonnull json) {
                QWLog(@"collect结果===%@",json[@"msg"]);
                [QWShowMessage showMessage:[NSString stringWithFormat:@"%@",json[@"msg"]]];
                [self.collectBtn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"收藏"]] forState:UIControlStateSelected];
            } failure:^(NSError * _Nonnull error) {
                
            }];
            
        }
        
    }else{
        if (self.collectBtn.selected) {
            
            NSString *collectURL = [QWHttpUrls CollectUrlWithOp:2 withcollect_type:3 Withcollect_id:_movieStr];
            NSMutableDictionary *params = [[NSMutableDictionary alloc]init];
            [params setValue:[QWAccountModel sharedModel].uid forKey:@"uid"];
            [QWHttpTool postmanager:collectURL params:params success:^(id  _Nonnull manager, id  _Nonnull json) {
                QWLog(@"collect结果===%@",json[@"msg"]);
                [QWShowMessage showMessage:[NSString stringWithFormat:@"%@",json[@"msg"]]];
                [self.collectBtn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"收藏"]] forState:UIControlStateSelected];
            } failure:^(NSError * _Nonnull error) {
                
            }];
        }else{
            NSString *collectURL = [QWHttpUrls CollectUrlWithOp:1 withcollect_type:3 Withcollect_id:_movieStr];
            NSMutableDictionary *params = [[NSMutableDictionary alloc]init];
            [params setValue:[QWAccountModel sharedModel].uid forKey:@"uid"];
            [QWHttpTool postmanager:collectURL params:params success:^(id  _Nonnull manager, id  _Nonnull json) {
                QWLog(@"collect结果===%@",json[@"msg"]);
                [QWShowMessage showMessage:[NSString stringWithFormat:@"%@",json[@"msg"]]];
                [self.collectBtn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"已收藏"]] forState:UIControlStateSelected];
            } failure:^(NSError * _Nonnull error) {
                
            }];
            
        }
        
    }
}