我有我的表视图,其中的单元格添加了UILongPressGestureRecognizer。问题是,一旦它触摸到一个单元格,它就会被高亮显示,但一旦我的长手势开始(按住按钮),高亮显示就会消失。这个手势有效,而且它仍然被握住,但用户有点困惑,因为他们不知道它是否仍然被握住。如何使单元格在整个保持期间保持高亮显示。
某些代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
//add long press gesture for the audio AB (eventually VC and TP as well) list
//so that users can hold the cell and after 5 seconds have the dialpad for editing that entry
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleLongPress:)];
longPress.minimumPressDuration = 1;
[cell addGestureRecognizer:longPress];
}
cell.textLabel.text = [self.tableArray objectAtIndex:indexPath.row];
return cell;
}
- (void)handleLongPress:(UILongPressGestureRecognizer*)sender
{
//used to get indexPath of cell pressed
UITableViewCell *cell = (UITableViewCell *)[sender view];
//get the indexPath of cell pressed
NSIndexPath *indexPath = [self.myTableView indexPathForCell:cell];
//use the index press to figure out the proper join to hold
self.sharedJoinNumber = indexPath.row+286 ;
}
我确实通过使用解决了这个问题
//highlight the apprioriate cell
[self.myTableView selectRowAtIndexPath:indexPath animated:FALSE scrollPosition:UITableViewScrollPositionNone];
- (void)handleLongPress:(UILongPressGestureRecognizer*)sender
之后
然而,现在如果取消了保留,则需要对单击的下一个单元格进行双重粘贴以突出显示。基本上,长按取消后的下一次敲击不会引起注意。但我认为这是一个单独的问题,我会相应地提出。上面的代码确实解决了我的问题