以下是当前tableView的外观。
我想要做的是不按顺序编辑Cell。我希望24出现在第1轮而不是第2轮,它出现并且G2有更新延迟,所以它更新了在比赛1之前玩过的轮次,而比赛3在比赛2之后是1轮。因此G1的更新将正常,每个新的tableViewCell创建一个新的回合,但是对于游戏2,第一个输入将在第1轮显示如下,而第1轮在第2轮。
这是我当前配置tableViewCell的方法。
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
NSIndexPath *g2IndexPath = [NSIndexPath indexPathForRow:(indexPath.row)-1 inSection:0];
if ([p1G1ScoreArray count] > 0 && [p1G1ScoreArray count] >= indexPath.row){
UILabel *label1 = (UILabel *)[cell.contentView viewWithTag:1];
NSString *label1String = [p1G1ScoreArray objectAtIndex:indexPath.row];
[label1 setText:label1String];
}
if ([p2G1ScoreArray count] > 0 && [p2G1ScoreArray count] >= indexPath.row ){
UILabel *label2 = (UILabel *)[cell.contentView viewWithTag:2];
NSString *label2String = [p2G1ScoreArray objectAtIndex:indexPath.row];
[label2 setText:label2String];
}
if ([p1G2ScoreArray count] >0 && g2RowIndex >= 0 &&[p1G2ScoreArray count] >= g2IndexPath.row){
UILabel *label3 = (UILabel *)[cell.contentView viewWithTag:3];
NSString *label3String = [p1G2ScoreArray objectAtIndex:(indexPath.row)-1];
[label3 setText:label3String ];
}
if ([p2G2ScoreArray count] >0 && g2RowIndex >= 0 &&[p2G2ScoreArray count] >= g2IndexPath.row){
UILabel *label4 = (UILabel *)[cell.contentView viewWithTag:4];
NSString *label4String = [p2G2ScoreArray objectAtIndex:g2IndexPath.row];
[label4 setText:label4String];
}
if ([p1G3ScoreArray count] >0 &&[p1G3ScoreArray count] >= indexPath.row){
UILabel *label5 = (UILabel *)[cell.contentView viewWithTag:5];
NSString *label5String = [p1G3ScoreArray objectAtIndex:indexPath.row];
[label5 setText:label5String];
}
if ([p2G3ScoreArray count] >0 &&[p2G3ScoreArray count] >= indexPath.row){
UILabel *label6 = (UILabel *)[cell.contentView viewWithTag:6];
NSString *label6String = [p2G3ScoreArray objectAtIndex:indexPath.row];
[label6 setText:label6String];
}
UILabel *roundTrackerLabel = (UILabel *)[cell.contentView viewWithTag:10];
NSString *roundTrackerLabelString = [NSString stringWithFormat:@"Round %d", indexPath.row +1];
[roundTrackerLabel setText:roundTrackerLabelString];
return cell;
}
修改
以下是数据的添加方式
- (IBAction)addNewRoundButtonPressed:(id)sender {
i++;
g2RowIndex ++;
j = i -2;
[p1G1ScoreArray addObject:[NSString stringWithFormat:@"%d", 2+i]];
if (g2RowIndex >= 0){
[p1G2ScoreArray addObject:[NSString stringWithFormat:@"%d", 22+i]];
}
[self.tableView reloadData];
}
答案 0 :(得分:1)
从这里查看代码,我建议只是将每个新输入添加到数组中,不要担心索引。至于你的检查,请为每个数组尝试此方法。
if ([p1G1ScoreArray count] > indexPath.row){
UILabel *label1 = (UILabel *)[cell.contentView viewWithTag:1];
NSString *label1String = [p1G1ScoreArray objectAtIndex:indexPath.row];
[label1 setText:label1String];
}
每个数组的索引都是count-1,因为数组的作用是偏离第一个项目的偏移量。 =项目正在抛弃支票。