2011-11-03 48 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 
    } 
} 

(未测试)。