2010-01-26 90 views
1

編輯的UITableViewCell的財產我知道這將是建立單元這種方法如何在其他方法

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

例如,如果我想在

tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 

編輯細胞的財產我怎樣才能訪問我選擇的單元格?

回答

2

你可以用下面的方法獲取可視細胞中的UITableView:

-(UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath 

返回值:表示表或爲零的 細胞的對象,如果該細胞 是不可見或indexPath是出 範圍。

因此,在您didSelectRow方法,你將有類似的信息(你可能需要細胞的selectionStyle設置爲UITableViewCellSelectionStyleNone進行更改正確顯示):

- tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 
    UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath]; 
    if (cell != nil){ 
     cell.textLabel.textColor = [UIColor redColor]; 
    } 
} 

或者你也可以繼承的UITableViewCell,實現- (void)setSelected:(BOOL)selected animated:(BOOL)animated方法並在那裏改變單元屬性。

+0

請問你能告訴我一些例子給我第一個答案嗎?我想你告訴我實現自定義UITableViewCell,然後重寫 - (void)setSelected:(BOOL)選擇動畫:(BOOL)動畫 來處理對嗎? – RAGOpoR 2010-01-26 10:52:46

+0

是的,你對第二部分 – Vladimir 2010-01-26 10:58:59

+0

謝謝弗拉基米爾 – RAGOpoR 2010-01-26 11:37:16