iPhone:修改在didSelectRowAtIndexPath中选择的单元格

时间:2011-04-27 14:12:14

标签: iphone uitableview

我有一个包含用户可以选择的条目的表,当点击它们时,UILabel应该转到UITextField,这样用户就可以编辑该行的值。

-(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
    }
}

出于任何原因,似乎我对控件的更改未得到应用。

这里有任何提示吗? Thx提前

2 个答案:

答案 0 :(得分:7)

您是否尝试过应用更新后致电reloadRowsAtIndexPaths:withRowAnimation:?像:

-(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];
    }
}

通常,除非您明确告诉表重新加载该单元格(或通过调用reloadData重新加载所有内容),否则不会显示对显示的单元格所做的更新。

答案 1 :(得分:0)

我的解决方案是最后插入一个额外的标志,告诉我,如果我处于编辑模式。在cellForRowAtIndexPath中,我正在检查此标志并设置Label / Textfield的可见性。

不是真正的正确方法,但它让我不再花费更多时间来讨论这个话题。

感谢你的建议。