Iphone 如何在UITableViewController中检测已选中但未单击的单元格
我对UITableViewCells有两种设计,一种用于选定的单元格,另一种用于未选定的单元格。我可以检测到在这些事件中选择和取消选择了一个单元格,以修改其设计:Iphone 如何在UITableViewController中检测已选中但未单击的单元格,iphone,objective-c,ios,cell,Iphone,Objective C,Ios,Cell,我对UITableViewCells有两种设计,一种用于选定的单元格,另一种用于未选定的单元格。我可以检测到在这些事件中选择和取消选择了一个单元格,以修改其设计: - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSInde
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
但是,当用户点击并按住单元格时,该单元格将高亮显示,但这些事件均未激活,因此我无法正确地重新绘制UITextLabel的阴影,因为UITitleLabel具有方法:titleLabel.highlightedTextColor,但没有方法titleLabel.highlightedShadowColor
在图中:
1 - Unselected cell
2 - Selected cell
3 - Tap & hold cell, with ugly shadows.
如何检测用户点击并按住单元格?您可以使用如下方法:
将手势添加到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
}
}
(未经测试)