我想在UITableViewController中捕获触摸点的x位置。
Web中描述的最简单的解决方案是UITapGestureRecognizer:enter link description here
但是在这种情况下,didSelectRowAtIndexPath被停止了。
您如何使用这两个事件,或者如何在singleTapGestureCaptured内部获取(NSIndexPath *)indexPath参数?
问候
[编辑]
我无法回答我的问题。
解决方案是:
NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:touchPoint]
最佳答案
我怀疑OP仍在等待答案,但为了将来的搜索者受益:
您可以在单元格内抓取touch事件,采取行动,然后将其丢弃或沿链向上传递:
@interface MyCell : UITableViewCell
// ...
@end
@implementation MyCell
// ...
- (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event
{
UITouch* touch = [[event allTouches] anyObject];
CGPoint someLocation = [touch locationInView: someView];
CGPoint otherLocation = [touch locationInView: otherView];
if ([someView pointInside: someLocation: withEvent: event])
{
// The touch was inside someView. Do some stuff,
// but don't invoke tableView:didSelectRowAtIndexPath: on the delegate.
}
else if ([otherView pointInside: otherLocation: withEvent: event])
{
// The touch was inside otherView. Do other stuff.
// Send the touch on for processing, and tableView:didSelectRowAtIndexPath: handling.
[super touchesBegan: touches withEvent: event];
}
else
{
// Send the touch on for processing, and tableView:didSelectRowAtIndexPath: handling.
[super touchesBegan: touches withEvent: event];
}
}
@end
关于iphone - iPhone:UITableViewController中的触摸点捕获,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8955101/