質問

I have UITableView with prototype cell.I have a label in cells with various values(text value). when add a new row, some of labels in new rows created with previous cell values not default values:

What can i do?

Is my question clear?

This is my code:

- (void)viewDidLoad
{
    [super viewDidLoad];

    gamers = [[NSMutableArray alloc] initWithObjects:@"Player1",@"Player2", nil];
}

- (IBAction)btnAddRow:(id)sender {
    [gamers addObject:@"new player"];
    [_tableView reloadData];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *tableIdentifier = @"gamerCell";
    nTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tableIdentifier];
    if (cell == nil) {
        cell = [[nTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:tableIdentifier];
    }
    cell.lblTitle.text = [gamers objectAtIndex:indexPath.row];

    return cell;
}
役に立ちましたか?

解決

Please find the updated project in the link

UITableView-dynamic-row-buttons

Hope this helps.

他のヒント

Where do you update the score? if you are not doing, make, according to your logic, and then set this value in

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *tableIdentifier = @"gamerCell";
    nTableViewCell *cell = (nTableViewCell *)[tableView dequeueReusableCellWithIdentifier:tableIdentifier];
    if (cell == nil) {
        cell = [[nTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:tableIdentifier];
    }
    cell.lblTitle.text = [gamers objectAtIndex:indexPath.row];
    cell.lblScore.text = [NSString stringWithFormat:@"%i", (int)scoreProperty]; 
    return cell;
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top