Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone: Modify a cell selected in didSelectRowAtIndexPath

I have a table with entries which the user can select and when clicking on them the UILabel should turn to a UITextField so the user can edit the value of that row.

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.section == 1 &&
       indexPath.row < [item.entries count])
    {
        ListDetailCell *tmpCell = ((ListDetailCell*)[self tableView:tvEntries cellForRowAtIndexPath:indexPath]);
        tmpCell.lbTitle.hidden = true;  // <- cell to hide
        tmpCell.tfTitle.hidden = false; // <- textfield to show
    }
}

For any reasons it seems that my changes on the controls don't get applied.

Any hints here? Thx in advance

like image 254
Max Avatar asked Apr 27 '11 14:04

Max


1 Answers

Have you tried calling reloadRowsAtIndexPaths:withRowAnimation: after applying your updates? Like:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.section == 1 &&
       indexPath.row < [item.entries count])
    {
        ListDetailCell *tmpCell = ((ListDetailCell*)[self tableView:tvEntries cellForRowAtIndexPath:indexPath]);
        tmpCell.lbTitle.hidden = true;  // <- cell to hide
        tmpCell.tfTitle.hidden = false; // <- textfield to show

        //reload the cell
        [tableView reloadRowsAtIndexPaths: [NSArray arrayWithObject: indexPath]
         withRowAnimation: UITableViewRowAnimationNone];
    }
}

In general, updates made to a displayed cell will not appear unless you explicitly tell the table to reload that cell (or to reload everything by calling reloadData.

like image 69
aroth Avatar answered Sep 22 '22 12:09

aroth