私の問題は次のとおりです。変更可能な配列をに割り当てて、cellForRowAtIndexPath
各配列オブジェクトをセルに表示します。これまでのところ、セルは期待どおりに表示されています。今、私は最初のセルに(条件に従って)aを表示したいUILabel
ので、他の可変配列オブジェクトは2番目のセル、3番目などにシフトされます。問題は、その条件をテストすると、 true の場合、は最初のオブジェクトとともにUILabel
最初のセルに表示されます。実際には、2 つの要素が同じセルにありますが、これは私が期待するものではありません。(条件が true の場合) すべての要素をシフトして、最初のセルを.UIlabel
私が期待するものを私に与えない私の関連コードはこれです:
- (UITableViewCell*)tableView:(UITableView *)_tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:@"any-cell"];
// Add and display the Cell
cell.tag = [indexPath row];
NSLog(@"cell.tag= %i",cell.tag);
//test the condition, if it's ok, then add the label to the first cell
if ([self isNoScoreLabelDisplayed] && cell.tag==0) {
UILabel *lbl=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 220, 50)];
[lbl setBackgroundColor:[UIColor greenColor]];
[cell addSubview:lbl];
}
cell.tag = [self isNoScoreLabelDisplayed]?[indexPath row]+1:[indexPath row];//here i wanted to shift the tags in case the condition is true, so that all the elements will be displayed from the second cell. But seems not doing what i want :(
//
if (indexPath.row < cellList.count) {
[cell addSubview:[cellList objectAtIndex:[indexPath row]]];//cellList is the mutable array from which i get all the elements to display in the cells
}else{
[cell addSubview:nextButton];
}
return cell;
}
私のロジックに何か欠けていますか?事前に感謝します。