当UITableViewCells滚动屏幕时,防止UITableView更新

时间:2013-11-24 18:41:09

标签: objective-c uitableview

我正在尝试使UITableView在每个tableview单元格上显示标签,UISegmentedControl和UITextField。这就是我目前正在做的事情:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    UILabel *name = (UILabel *)[cell viewWithTag:1];
    UISegmentedControl *phase = (UISegmentedControl *)[cell viewWithTag:2];

    NSString *currentPhaseString = [[_data objectForKey:@"phase"] objectForKey:[NSString stringWithFormat:@"%ld", indexPath.row + 1]];
    int currentPhase = [currentPhaseString floatValue];

    [phase setTitle:[NSString stringWithFormat:@"%d", currentPhase] forSegmentAtIndex:0];
    [phase setTitle:[NSString stringWithFormat:@"%d", currentPhase + 1] forSegmentAtIndex:1];
    [phase setSelectedSegmentIndex:0];

    name.text = [[_data objectForKey:@"players"] objectForKey:[NSString stringWithFormat:@"%ld", indexPath.row + 1]];
    return cell;
}

问题是当用户向下滚动并向上滚动时,对从屏幕滚动的单元格的任何更改都不会被保存。当用户将它们从屏幕滚动并重新打开时,有没有办法阻止细胞重新创建?谢谢!

0 个答案:

没有答案