2011-11-03 46 views
3

enter image description here如何檢測電池的選擇,但在一個UITableViewController

不點擊我有兩個設計爲UITableViewCells,一個用於選定的細胞和其他未選定單元格。我可以檢測到小區選擇和取消這些事件來修改自己的設計:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath 

但是,當用戶水龍頭&持有細胞,細胞被突出顯示,但沒有這些事件被激活,所以我不能重新繪製UITextLabels的陰影,因爲UITitleLabels的方法是:titleLabel.highlightedTextColor,但不是方法titleLabel.highlightedShadowColor。

在圖像:

1 - Unselected cell 
2 - Selected cell 
3 - Tap & hold cell, with ugly shadows. 

我怎樣才能檢測到用戶水龍頭&持有細胞?

回答

7

你可以使用一個UILongPressGestureRecognizer這樣的:

手勢添加到細胞中的cellForRowAtIndexPath:

UILongPressGestureRecognizer *twoSecPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handlePress:)]; 
      [twoSecPress setMinimumPressDuration:2]; 
      [cell addGestureRecognizer: twoSecPress]; 
      [twoSecPress release]; 

處理選擇

-(void) handlePress:(UILongPressGestureRecognizer *)recognizer { 
if (recognizer.state == UIGestureRecognizerStateBegan) { 
     UITableViewCell *cellView=(UITableViewCell *)recognizer.view; 
     //do your stuff 
    } 
} 

(未測試)。