2011-04-27 53 views
5

我有一個用戶可以選擇的條目表,當點擊它們時,UILabel應該轉向UITextField,以便用戶可以編輯該行的值。iPhone:修改在didSelectRowAtIndexPath中選擇的單元格

-(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提前

+0

我不知道在你的情況下它是否合適,但是你不能簡單地使用帶有佔位符的UITextField而不是UILabel嗎? – 2011-04-27 14:16:56

+0

是的,我已經想過這個。但據我所知,我不能讓一個文本字段看起來像一個簡單的標籤(無邊界) – Max 2011-04-27 17:31:47

回答

0

我的解決辦法是在最後。插入一個額外的標誌,告訴我,如果我在編輯模式或不在。在cellForRowAtIndexPath我檢查此標誌,並設置標籤/文本字段的可見性。

不是一個真正的方式,但它節省了我的開支關於這個話題還有更多的時間。

Thx爲您的建議。

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重裝一切

+0

儘管事實,我沒有連接我的UITextField,重新加載的單元格(我嘗試'reloadData','' reloadInputViews'和'reloadRowsAtIndexPath')不適合我。 – Max 2011-04-27 17:17:03

相關問題