2012-12-06 14 views
1

我需要獲取當前選中的UITableViewCell作爲其點擊。所以,在我的手指觸摸屏幕/電池我想運行從中我能說簡單的東西作爲一種方法:獲取選定的UITableViewCell在接觸下?

selectedCell = cell; 

cell是作爲一個副本我存儲一個我只是挖掘和selectedCell

我正在使用自定義子類UITableViewCell這就是爲什麼我覺得我有麻煩,但如果你能幫助我找到一種方法做到這一點,我將非常感激,謝謝。

回答

1

TouchDown的
- 的setSelected:動畫:被稱爲對細胞本身上觸摸到這裏,你可以通知單元委託

- (void)setSelected:(BOOL)selected animated:(BOOL)animated { 
    [self.delegate willSelectCell:self]; 
} 

聲明定製單元委託作爲小區的物業

@property id<MyCellDelegate> delegate; 

潤色
保存細胞在委託

- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
_selectedCell = [aTableView cellForRowAtIndexPath:indexPath]; 
} 

只注意一個事實,即細胞意見可重複使用

+0

我想這可能是建議,對不起,我沒有提到,但可能是因爲我的自定義單元格,這不會被按下我的細胞調用。有一個自定義的單元格會對此產生什麼影響? –

+1

不是'didSelectRowAtIndexPath:'觸摸起來觸發嗎? – dasblinkenlight

+0

@dasblinkenlight很可能,對不起 –

12

只實現setHighlighted:動畫:方法上這樣的自己定製的tableview細胞。

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated { 
    [super setHighlighted:highlighted animated:animated]; 

    NSLog (@"setHighlighted:%@ animated:%@", ([email protected]"YES":@"NO"), ([email protected]"YES":@"NO")); 
} 
相關問題