我正在尝试向 tableViewCell 添加滑动手势识别器,但它不起作用。
这是我创建单元格的方式:
CellIdentifier = @"EventsSentCell";
nibObjcet = [[NSBundle mainBundle] loadNibNamed:@"EventsSentCell" owner:self options:nil];
EventsSentCell *cell = [[EventsSentCell alloc] init];
cell = (EventsSentCell *)[nibObjcet objectAtIndex:0];
这就是我的单元格在 .m 文件中的启动方式:
-(id)init{
self = [super init];
if (self) {
leftSwipe = [[UISwipeGestureRecognizer alloc] init];
leftSwipe.direction= UISwipeGestureRecognizerDirectionLeft;
[leftSwipe addTarget:self action:@selector(swipedLeft)];
[self addGestureRecognizer:leftSwipe];
}
return self;
}
这就是我在 .h 文件中声明手势识别器的方式:
@property (nonatomic,strong) IBOutlet UISwipeGestureRecognizer *leftSwipe;
但由于某种原因,我的方法没有被调用。
有任何想法吗?
谢谢
我试过把下面的代码:
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
NSLog(@"%@",gestureRecognizer);
return YES;
}
我向左滑动后得到的结果是:
<UILongPressGestureRecognizer: 0xa9d99a0; state = Possible; view = <UITableViewCellContentView 0xa9d8ce0>; target= <(action=_longPressGestureRecognized:, target=<EventsSentCell 0xa9d8bb0>)>>