pig*_*ack 5 iphone objective-c uitableview ios
正如问题所述,我想在UITableViewCell上实现两个不同的操作以进行点击和长按.
我想我必须在每个阶段取消选择行并在此处放置任何函数:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:NO];
}
Run Code Online (Sandbox Code Playgroud)
然后从故事板中添加Tap Gestures,但当我将动作拖动到原型单元格时,Storyboard会给我一个错误.提示?
ank*_*eMe 14
试试这个 -
在您的cellForRowAtIndexPath方法中,您可以单独添加轻击手势和长按手势,然后实施它们.这样你的didselect功能将不再需要,你不需要deSelect任何东西.
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cellTapped:)];
tapGestureRecognizer.numberOfTapsRequired = 1;
tapGestureRecognizer.numberOfTouchesRequired = 1;
cell.tag = indexPath.row;
[cell addGestureRecognizer:tapGestureRecognizer];
UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc]
initWithTarget:self action:@selector(handleLongPress:)];
lpgr.minimumPressDuration = 1.0; //seconds
[cell addGestureRecognizer:lpgr];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
Run Code Online (Sandbox Code Playgroud)
现在,
-(void)handleLongPress:(UILongPressGestureRecognizer *)longPress
{
// Your code here
}
-(void)cellTapped:(UITapGestureRecognizer*)tap
{
// Your code here
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15395 次 |
| 最近记录: |