如何将滑动手势添加到 UITableView 单元格?

How to add Swipe Gestures to UITableView cell?(如何将滑动手势添加到 UITableView 单元格?)
本文介绍了如何将滑动手势添加到 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 单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
How to stop UIBarButtonItem text from truncating?(如何阻止UIBarButtonItem文本被截断?)
java.lang.IllegalStateException: SimpleTypeImpl should not be created for error type(异常:不应为错误类型创建SimpleTypeImpl)
Android IllegalArgumentException: The tag for fragment_XXX is invalid. Received: layout-sw600dp/fragment_XXX_0(Android IlLegalArgumentException:Fragment_XXX的标签无效。收到:Layout-sw600dp/Fragment_XXX_0)
iOS convert audio sample rate from 16 kHz to 8 kHz(IOS将音频采样率从16 kHz转换为8 kHz)
Enforcing an audio sampling rate in iOS(在iOS中强制音频采样率)