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

Max*_*Max 5 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
    }
}
Run Code Online (Sandbox Code Playgroud)

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

这里有什么提示吗?Thx提前

aro*_*oth 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];
    }
}
Run Code Online (Sandbox Code Playgroud)

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


Max*_*Max 0

我的解决方案是最后插入一个附加标志,告诉我是否处于编辑模式。在 cellForRowAtIndexPath 中,我正在检查此标志并设置标签/文本字段的可见性。

这不是一个真正正确的方法,但它使我免于在这个主题上花费更多时间。

谢谢你的建议。