objective c - iOS : UITableView reloaddata do not reload all cell -
here scenario,my view controller receive data after modal segue,i called reloaddata method in viewwillappear.i mean create tableview display 4 rows @ most.first row show same content.if data more 4, table view display first 2 datas,the last row display there more data.if data less 4,table view display first row plus data rows. here code:
- (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { if (_assmeblemodel.cityid.count < 4) { return _assmeblemodel.cityid.count + 1; }else { return 4; } } - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellid = @"citybarcellid"; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellid]; if (!cell) { cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellid]; if (0 == indexpath.row) { uiimageview *markerimageview = [[uiimageview alloc] initwithimage:[uiimage imagenamed:@"map marker"]]; markerimageview.frame = cgrectmake(20, 5, 30, 30); uilabel *citylabel = [[uilabel alloc] initwithframe:cgrectmake(70, 15, 80, 20)]; citylabel.textcolor = [uicolor whitecolor]; citylabel.backgroundcolor = [uicolor clearcolor]; citylabel.text = @"编辑地点"; [cell addsubview:markerimageview]; [cell addsubview:citylabel]; } if (0 != indexpath.row && _assmeblemodel.cityid.count < 4) { uiimageview *markerimageview = [[uiimageview alloc] initwithimage:[uiimage imagenamed:@"marker"]]; markerimageview.frame = cgrectmake(20, 5, 30, 30); uilabel *citylabel = [[uilabel alloc] initwithframe:cgrectmake(70, 15, 80, 20)]; citylabel.textcolor = [uicolor whitecolor]; citylabel.backgroundcolor = [uicolor clearcolor]; weatherinfomodel *infomodel = _assmeblemodel.cityid[indexpath.row - 1]; citylabel.text = infomodel.cityname; [cell addsubview:markerimageview]; [cell addsubview:citylabel]; } if (0 != indexpath.row && 3 != indexpath.row && _assmeblemodel.cityid.count >= 4) { uiimageview *markerimageview = [[uiimageview alloc] initwithimage:[uiimage imagenamed:@"marker"]]; markerimageview.frame = cgrectmake(20, 5, 30, 30); uilabel *citylabel = [[uilabel alloc] initwithframe:cgrectmake(70, 15, 80, 20)]; citylabel.textcolor = [uicolor whitecolor]; citylabel.backgroundcolor = [uicolor clearcolor]; weatherinfomodel *infomodel = _assmeblemodel.cityid[indexpath.row - 1]; citylabel.text = infomodel.cityname; [cell addsubview:markerimageview]; [cell addsubview:citylabel]; } if (3 == indexpath.row && _assmeblemodel.cityid.count >= 4) { uiimageview *markerimageview = [[uiimageview alloc] initwithimage:[uiimage imagenamed:@"more"]]; markerimageview.frame = cgrectmake(20, 5, 30, 30); uiimageview *arrowimageview = [[uiimageview alloc] initwithimage:[uiimage imagenamed:@"expand arrow"]]; arrowimageview.frame = cgrectmake(110, 5, 30, 30); uilabel *citylabel = [[uilabel alloc] initwithframe:cgrectmake(70, 15, 80, 20)]; citylabel.textcolor = [uicolor whitecolor]; citylabel.backgroundcolor = [uicolor clearcolor]; citylabel.text = [nsstring stringwithformat:@"显示其他%lu个项目",(unsigned long)(_assmeblemodel.cityid.count - 3)]; [cell addsubview:arrowimageview]; [cell addsubview:markerimageview]; [cell addsubview:citylabel]; } i add data 1 @ time,every time add data,it called viewdidappear.i thought tableview update every cell cause of called reloaddata.but appear not,it seem reloaddata update add new one.and when data more 4, program execute second if,my last cell not display right.
i totally confused,someone me please,thanks bunch.
Comments
Post a Comment