美文网首页
iOS tableview的第二页数据刷新特定某个cell数据的

iOS tableview的第二页数据刷新特定某个cell数据的

作者: Onlyoner | 来源:发表于2017-03-31 18:11 被阅读0次

    解决多页面cell刷新数据位置变的问题。

    看首页接口(示例)
    https://xxxxssssssss/heal/api/heal/plan/list
    参数:

    QQ20170331-174946.png
    QQ20170331-174234@2x.png

    这个问题产生的背景是:

    1.当第一次请求接口产生的20条数据。再添加计划按钮执行后,
    要想刷新当前页面为最新数据,以获得当前计划的userplanid来作为用户添加过的唯一标识,
    根据这个标识去设置 ➕ 按钮是否显示。这20条数据构成的是第一页,添加后进行刷新数据相当于,上拉刷新请求,参数还是第一页请求20条即可;

    {
      "page_info": {
        "pageNo": 1,
        "pageSize": 20,
        "count": 34
      },
      "ret_msg": "",
      "ret_code": "0",
      "page_data": [
        {
          "id": "e738c5a9794c480cb74cd102afb8d5fd",
          "planname": "缓解大脑疲劳",
          "plandec": "本方案选用脑户穴、风池穴、络却穴、角孙穴、神庭穴5个穴位。脑户穴和神庭穴是督脉穴位,督脉有分支络肾、贯心,养髓安神;角孙穴是手少阳三焦经的穴位,三焦经有通行元气的功能,元气入脑养髓;足太阳膀胱经脉气的气化功能由络却穴进入颅内保障思维运行的能量供应;风池穴是足少阳胆经的穴位,调用少阳之气支持思维的迅捷灵活运行",
          "planimg": "/heal/userfiles/images/FMT/FMT_head_1242x729_脑部头部疲劳封面.jpg",
          "planimg2": "/heal/userfiles/images/FMT/FMT_head_1242x729_脑部头部疲劳封面.jpg",
          "coursecnt": "3",
          "actcnt": "15",
          "acupointcnt": "15",
          "plantype": "0",
          "nounit": "天",
          "cpdays": "3",
          "cptime": "5",
          "daytime": "2",
          "planlev": "2",
          "senddatetime": "2017-03-23 16:38:05",
          "version": "1.02",
          "myplan": "1",
          "userplanid": "b9e22dd089954cf9811a9c00686296d1",
          "mycpdays": "0",
          "plandeclist": [
            {
              "plandecl": "本方案选用脑户穴、风池穴、络却穴、角孙穴、神庭穴5个穴位。脑户穴和神庭穴是督脉穴位,督脉有分支络肾、贯心,养髓安神;角孙穴是手少阳三焦经的穴位,三焦经有通行元气的功能,元气入脑养髓;足太阳膀胱经脉气的气化功能由络却穴进入颅内保障思维运行的能量供应;风池穴是足少阳胆经的穴位,调用少阳之气支持思维的迅捷灵活运行"
            },
            {
              "plandecl": "【推荐频次】\r\n1.每天2次\r\n2.脑紧张疲劳时,可随时使用方案"
            },
            {
              "plandecl": "【按摩要点】\r\n1.身体处于放松状态\r\n2. 按摩力量不要过大,不要弄伤自己,建议使用3分力 \r\n3. 按摩时,手指累了,可以换一个手指继续按摩"
            },
            {
              "plandecl": "【按摩禁忌】\r\n1.有溃破、伤肿的部位,不要伤及破损,可以按摩对侧的位置\r\n2.医嘱建议不适宜按摩的人群"
            },
            {
              "plandecl": "【友情提示】\r\n1.按摩过程中可能出现穴位酸痛、胀痛,这是穴位已经发生瘀赌,应长期坚持按摩,消散瘀赌,从而化解由此累积的疾病隐患\r\n2.有严重头痛、头晕症状的,请及时到医院就诊,查明病因,遵医嘱,积极治疗\r\n3. 本方案可长期使用"
            }
          ]
        },
        {
          "id": "08bf634acad947e096972321a4a09701",
          "planname": "缓解颈疲劳",
          "plandec": "",
          "planimg": "/heal/userfiles/images/FMT/颈椎.jpeg",
          "planimg2": "/heal/userfiles/images/FMT/颈椎.jpeg",
          "coursecnt": "3",
          "actcnt": "15",
          "acupointcnt": "15",
          "plantype": "0",
          "nounit": "天",
          "cpdays": "3",
          "cptime": "6",
          "daytime": "2",
          "planlev": "2",
          "senddatetime": "2017-02-19 08:34:39",
          "version": "1.03",
          "myplan": "1",
          "userplanid": "15843782c91e4dfda02a0441442fecc5",
          "mycpdays": "0",
          "plandeclist": [
            {
              "plandecl": "【说明】\r\n本计划选用“祛风解肌养颈椎”近端取穴方案,5个穴位:大椎穴、风府穴、风池穴、完骨穴、颈百劳。其中大椎穴和风府穴是督脉的穴位,督脉总督一身阳气,滋养颈椎;风池穴、完骨穴是足少阳胆经的穴位,少阳经的开合特点,以强化颈椎的活动功能;颈百劳是经外奇穴,选用拿揉颈百劳的手法,放松颈部的肌肉群;在中华传统文化对人体的认知体系里,风寒的侵袭滞留,是疼痛的重要隐患,风池穴、风府穴的选用,可以祛风消痛"
            },
            {
              "plandecl": "【推荐频次】\r\n1.每天2次\r\n2.颈部紧张、疲劳、疼痛时,可随时使用方案"
            },
            {
              "plandecl": "【按摩要点】\r\n1.颈肩处于放松状态\r\n2. 按摩力量不要过大,不要弄伤自己,建议使用3分力\r\n3. 按摩时,手指累了,可以换一个手指按摩"
            },
            {
              "plandecl": "【按摩禁忌】\r\n1.有溃破、伤肿的部位,不要伤及破损,可以按摩对侧的位置\r\n2.医嘱建议不适宜按摩的人群"
            },
            {
              "plandecl": "【友情提示】\r\n1.按摩过程中可能出现局部酸痛、胀痛,是穴位已经瘀赌,应长期坚持按摩,消散瘀赌,从而化解由此累积的各类隐患\r\n2.有严重颈椎疼痛症状的,请及时到医院就诊,查明病因,遵医嘱,积极治疗"
            }
          ]
        },。。。。。。。。
    

    2.当处于第二页的时候,点击添加计划按钮 ➕ 时,
    再次请求数据的时候参数如果再是请求第一页的时候的就不行了,
    这时要根据当前页currentpage来算需要的数据条数,
    因为处于当前页的时候正常是40条数据了,所以这次请求就应传参数为pagesize = 40,
    而页码传写死的pageno= 1;

    {
      "page_info": {
        "pageNo": 1,
        "pageSize": 40,
        "count": 34
      },
      "ret_msg": "",
      "ret_code": "0",
      "page_data": [
        {
          "id": "e738c5a9794c480cb74cd102afb8d5fd",
          "planname": "缓解大脑疲劳",
          "plandec": "本方案选用脑户穴、风池穴、络却穴、角孙穴、神庭穴5个穴位。脑户穴和神庭穴是督脉穴位,督脉有分支络肾、贯心,养髓安神;角孙穴是手少阳三焦经的穴位,三焦经有通行元气的功能,元气入脑养髓;足太阳膀胱经脉气的气化功能由络却穴进入颅内保障思维运行的能量供应;风池穴是足少阳胆经的穴位,调用少阳之气支持思维的迅捷灵活运行",
          "planimg": "/heal/userfiles/images/FMT/FMT_head_1242x729_脑部头部疲劳封面.jpg",
          "planimg2": "/heal/userfiles/images/FMT/FMT_head_1242x729_脑部头部疲劳封面.jpg",
          "coursecnt": "3",
          "actcnt": "15",
          "acupointcnt": "15",
          "plantype": "0",
          "nounit": "天",
          "cpdays": "3",
          "cptime": "5",
          "daytime": "2",
          "planlev": "2",
          "senddatetime": "2017-03-23 16:38:05",
          "version": "1.02",
          "myplan": "0",
          "userplanid": "0",
          "mycpdays": "0",
          "plandeclist": [
            {
              "plandecl": "本方案选用脑户穴、风池穴、络却穴、角孙穴、神庭穴5个穴位。脑户穴和神庭穴是督脉穴位,督脉有分支络肾、贯心,养髓安神;角孙穴是手少阳三焦经的穴位,三焦经有通行元气的功能,元气入脑养髓;足太阳膀胱经脉气的气化功能由络却穴进入颅内保障思维运行的能量供应;风池穴是足少阳胆经的穴位,调用少阳之气支持思维的迅捷灵活运行"
            },
            {
              "plandecl": "【推荐频次】\r\n1.每天2次\r\n2.脑紧张疲劳时,可随时使用方案"
            },
            {
              "plandecl": "【按摩要点】\r\n1.身体处于放松状态\r\n2. 按摩力量不要过大,不要弄伤自己,建议使用3分力 \r\n3. 按摩时,手指累了,可以换一个手指继续按摩"
            },
            {
              "plandecl": "【按摩禁忌】\r\n1.有溃破、伤肿的部位,不要伤及破损,可以按摩对侧的位置\r\n2.医嘱建议不适宜按摩的人群"
            },
            {
              "plandecl": "【友情提示】\r\n1.按摩过程中可能出现穴位酸痛、胀痛,这是穴位已经发生瘀赌,应长期坚持按摩,消散瘀赌,从而化解由此累积的疾病隐患\r\n2.有严重头痛、头晕症状的,请及时到医院就诊,查明病因,遵医嘱,积极治疗\r\n3. 本方案可长期使用"
            }
          ]
        },。。。。。
    

    3.能理解多少算多少吧;
    下边上代码:

    /** 记录添加计划操作 */
    @property (nonatomic,assign) BOOL isAddPlan;
    - (void)loadNewPlan{
    ###这里这里!!!!!*************************
        _isAddPlan = NO;
        NSLog(@"下拉刷新");
        _page = 0;
        _pagesize = 20;
        NSLog(@"下拉更新显示第%d页",_page+1);//下拉刷新更新显示第一页的数据
        [self requestData:self.tb UP_Refresh:YES];
    }
    - (void)loadMorePlan{
       ###这里这里!!!!!*************************
        _isAddPlan = NO;
     
        NSLog(@"上拉加载");
        [self requestData:self.tb UP_Refresh:NO];
    }
    - (NSDictionary *)Parameters{
        NSDictionary *parameters = [NSDictionary dictionary];
        NSString *page = [NSString stringWithFormat:@"%d",_page + 1];
        NSString *pageSize = [NSString stringWithFormat:@"%d",_pagesize];
        if (_isAddPlan == YES) {
        ###这里这里!!!!!*************************
            parameters = @{
                           @"pageNo":@"1",
                           @"pageSize":[NSString stringWithFormat:@"%d",_page*20],
                           @"accesstoken":UserInfoShare.accesstoken
                           };
            return parameters;
    
        }
        if (!UserInfoShare_accesstoken) {
            parameters = @{
                           @"pageNo":page,
                           @"pageSize":pageSize
                           };
        } else {
            parameters = @{
                           @"pageNo":page,
                           @"pageSize":pageSize,
                           @"accesstoken":UserInfoShare.accesstoken
                           };
        }
        return parameters;
    
    }
    
    - (void)requestData:(UITableView *)tb UP_Refresh:(BOOL)upRefresh{
        HLWeakSelf;
        [[XDHTTPSessionManager shareManager] RequestWithType:XDHttpRequestTypePost UrlString:API_HomeUrl Parameters:[self Parameters] progress:^(NSProgress *progress) {
            
            
        } SuccessBlock:^(id responseObject) {
            NSLog_responseObject;
            if (ret_code_success) {
                if (upRefresh == YES) {
                    //下拉刷新显示第一页的数据
                    weakSelf.dataArraynet = [HLPlanManager mj_objectArrayWithKeyValuesArray:responseObject[@"page_data"]];
                    
                    
                }else if (upRefresh == NO){
                    //上拉加载
                    NSArray *newPlanArray = [HLPlanManager mj_objectArrayWithKeyValuesArray:responseObject[@"page_data"]];
                    [weakSelf.dataArraynet addObjectsFromArray:newPlanArray];
                    
                }
    ###这里这里!!!!!*************************
                if (_isAddPlan == YES) {
                    
                } else {
                    
                    _pagesize = [responseObject[@"page_info"][@"pageSize"] intValue];
                    _page_count =[responseObject[@"page_info"][@"count"] intValue];
                    _page = [responseObject[@"page_info"][@"pageNo"] intValue];
                }
            }else{
                //失败
                if(ret_wrong_accesstoken){
                    [weakSelf checkAccessToken_responseObject:responseObject andSuccess:^{
                        //重新请求
                        [weakSelf requestData:tb UP_Refresh:NO];
                    } andFailer:^{
                        [weakSelf loginoutFromRoot];
                    }];
                }else if (ret_code_failer){
    //                [MBProgressHUD showMessage:ret_msg];
                }
            }
            //                // ==写入文件
            
    
            BOOL isWriteSuess = [[weakSelf.dataArraynet yy_modelToJSONObject] writeToFile:weakSelf.Json_path atomically:YES];
            NSLog(@"发现计划列表写入文件%@",isWriteSuess ? [NSString stringWithFormat:@"成功 路径是%@",weakSelf.Json_path]:@"失败");
            upRefresh == YES?[tb.mj_header endRefreshing]:[tb.mj_footer endRefreshing];
            [tb reloadData];
            
        } FailureBlock:^(NSError *error) {
            
            upRefresh == YES?[tb.mj_header endRefreshing]:[tb.mj_footer endRefreshing];
            [tb reloadData];
            
        }];
        
        
    }
    
    #pragma mark - <UITableViewDelegate,UITableViewDataSource>
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
        static NSString *cellID = @"cellName";
        HLPlanTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
        if (cell == nil) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"HLPlanTableViewCell" owner:self options:nil] lastObject];
        }
        cell.progress.hidden = YES;
        [cell.addButton addTarget:self action:@selector(cellBtnClicked:event:) forControlEvents:UIControlEventTouchUpInside];
        cell.addButton.tag  = indexPath.row+100;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.manager = self.dataArraynet[indexPath.row];
    
        return cell;
        
    }
    - (void)cellBtnClicked:(id)sender event:(id)event
    {
        
        HLWeakSelf;
        [XDControl CheckshifouNeedToLoginBlock:^{
            //去登录
            HLLoginsViewController *loginVC = [HLLoginsViewController new];
            loginVC.isShow = YES;
            [weakSelf presentViewController:loginVC animated:YES completion:nil];
        } LoginSusess_Or_NoNeedLoginBlock:^{
             //登录成功  或者不需要登录 回来执行 该执行的 比如这里执行 添加
            NSSet *touches =[event allTouches];
            UITouch *touch =[touches anyObject];
            CGPoint currentTouchPosition = [touch locationInView:weakSelf.tb];
            NSIndexPath *indexPath= [weakSelf.tb indexPathForRowAtPoint:currentTouchPosition];
            if (indexPath!= nil)
            {
                NSLog(@"添加第:%ld行的ID给我的计划列表😄",(long)indexPath.row);
                NSString *addplanid = [weakSelf.dataArraynet[indexPath.row] id];
                //统计点击行为各属性被触发的次数  统计应用中“添加”事件发生的次数,以及添加的计划名字及id,那么在添加计划的函数里调用:
                NSDictionary *dict = @{@"planname" : [weakSelf.dataArraynet[indexPath.row] planname], @"id" : addplanid};
                [MobClick event:@"AddPlanName" attributes:dict];
                
                
                NSDictionary *parameters = @{
                                             @"accesstoken":UserInfoShare.accesstoken,
                                             @"planid":addplanid
                                             };
                HLWeakSelf;
                [[XDHTTPSessionManager shareManager] RequestWithType:XDHttpRequestTypePost UrlString:API_addMyplanUrl Parameters:parameters progress:^(NSProgress *progress) {
                    
                } SuccessBlock:^(id responseObject) {
                    //            responseObject=={
                    //                ret_msg = "wrong access token";
                    //                ret_code = "999"
                    //            }
                    
                    NSLog_responseObject;
                    if (ret_code_success) {
                        //加入计划成功
                        [MBProgressHUD showSuccess:ret_msg];
    ###这里这里!!!!!*************************
                        _isAddPlan = YES;
                        [weakSelf requestData:weakSelf.tb UP_Refresh:YES];
                        //               UIButton *button =  [self.view viewWithTag:indexPath.row+100];
                        //                button.hidden = YES;
                    }else if(ret_code_failer){
                        [MBProgressHUD showError:ret_msg];
                        //加入计划失败
                    }else if(ret_wrong_accesstoken){
                        [weakSelf checkAccessToken_responseObject:responseObject andSuccess:^{
                            //重新请求
                            [weakSelf cellBtnClicked:sender event:event];
                        } andFailer:^{
                            [weakSelf loginoutFromRoot];
                        }];
                    }
                    
                    
                } FailureBlock:^(NSError *error) {
                    
                }];
            }
    
        }];
    
        
    }
    
    

    相关文章

      网友评论

          本文标题:iOS tableview的第二页数据刷新特定某个cell数据的

          本文链接:https://www.haomeiwen.com/subject/pomvottx.html