Вопрос

Sorry if this question look stupid but after hours of digging and searching with no success, I need to ask it here for you help. I have a UITableViewController with 15 custom cell. Each cell has a UITextField inside.

here is the part of code:

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

    Static NSString *CellIdentifier = @"ADDFIELDCELL";
    AddListContentCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[AddListContentCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

    }


    [cell.myTextField setTag:[self.tagsArray objectAtIndex:indexPath.row] integerValue]];

    return cell;
}

The problem is when I type something in first cell (indexPath:0) after scroll down same text appear on 13th cell also. same mapping happens with 2nd and 14th cell.

I am really out of temper and do not what should I do. Any help will be appreciated.

Это было полезно?

Решение

The cell is being reused (hence the reuse identifier).

The textfield text for each cell needs to be linked to the datasource somehow (seems to be your tags array).

When you change the text on that cell, you have to modify the datasource text.

This way when the cell at index 2 rolls around, it will fill the textfield with whatever your tag item at index 2 of your datasource array has.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top