如何将滑动手势添加到 UITableView 单元格? [英] How to add Swipe Gestures to UITableView cell?

查看:19
本文介绍了如何将滑动手势添加到 UITableView 单元格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 cellForRowAtIndexPath

中添加了这段代码

UISwipeGestureRecognizer *gestureR = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom:)];[gestureR setDirection:UISwipeGestureRecognizerDirectionRight];//|UISwipeGestureRecognizerDirectionRight)];[单元格 addGestureRecognizer:gestureR];

它工作正常.但我想要 UISwipeGestureRecognizerDirectionLeft 所以像这样添加

[gestureR setDirection:UISwipeGestureRecognizerDirectionLeft|UISwipeGestureRecognizerDirectionRight)];

当我检查方向和状态时,我总是得到 3 = 3

- (void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer {NSLog(@"%d = %d",recognizer.direction,recognizer.state);}

如果我只应用一个手势,它就可以正常工作.我试图一个一个地添加两个手势.但它只会响应一个手势.

如何添加第二个手势.我直接将一个手势添加到 TableView 另一个手势到单元格,但现在使用.

解决方案

试试这个

<上一页>UISwipeGestureRecognizer* 手势R;手势R = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom)] autorelease];手势R.direction = UISwipeGestureRecognizerDirectionLeft;[查看 addGestureRecognizer:gestureR];手势R = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom)] autorelease];手势R.direction = UISwipeGestureRecognizerDirectionRight;//默认[查看 addGestureRecognizer:gestureR];

如果您想处理左右滑动的不同功能,只需更改选择器即可.

I added this code in cellForRowAtIndexPath

UISwipeGestureRecognizer *gestureR = [[UISwipeGestureRecognizer alloc]
                                             initWithTarget:self action:@selector(handleSwipeFrom:)];
        [gestureR setDirection:UISwipeGestureRecognizerDirectionRight];//|UISwipeGestureRecognizerDirectionRight)];
        [cell addGestureRecognizer:gestureR];

it works fine. But I want UISwipeGestureRecognizerDirectionLeft so Added like this

[gestureR setDirection:UISwipeGestureRecognizerDirectionLeft|UISwipeGestureRecognizerDirectionRight)];

When I check with direction and state I am always getting 3 = 3

- (void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer {    

    NSLog(@"%d = %d",recognizer.direction,recognizer.state);
}

if I apply only one Gesture it works fine. I tried to add two gestures one by one. but it will responding for only one gesture.

How to add second gestures. I added directly to one gesture to TableView another one to cell but now use.

解决方案

Try this

UISwipeGestureRecognizer* gestureR;
gestureR = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom)] autorelease];
gestureR.direction = UISwipeGestureRecognizerDirectionLeft;
[view addGestureRecognizer:gestureR];

gestureR = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom)] autorelease];
gestureR.direction = UISwipeGestureRecognizerDirectionRight; // default
[view addGestureRecognizer:gestureR];

If you want to handle different functionalities on left and right swipes, just change the selectors.

这篇关于如何将滑动手势添加到 UITableView 单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆