在iOS中获取UIGestureRecognizer的操作

我在NSLog中的 – tableView:didSelectRowAtIndexPath方法中打印了一个UITableviewCell的手势
<UIScrollViewPanGestureRecognizer: 0x11e92080; state = Possible; cancelstouchesInView = NO; delaystouchesEnded = NO; view = <UITableViewCellScrollView 0x11e94bf0>; target= <(action=handlePan:,target=<UITableViewCellScrollView 0x11e94bf0>)>>

我已将此UIScrollViewPanGestureRecognizer分配给UIGestureRecognizer以访问其属性,如下所示,

UIGestureRecognizer *myGes=[temp.gestureRecognizers objectAtIndex:1];

我能够访问’myGes’的所有属性

myGes.state;
 myGes.cancelstouchesInView;
 myGes.delaystouchesEnded;
 myGes.view;

除了一个名为target的属性.

有没有可能访问该属性?因为我需要执行该操作.

任何意见或建议将不胜感激.

先感谢您.

解决方法

有一种方法可以访问属性目标,但我不确定此方法是否会通过Apple批准过程.
NSMutableArray *targets = [myGes valueForKeyPath:@"_targets"];
id targetContainer = targets[0];//get first target for example
id targetofMyGes = [targetContainer valueForKeyPath:@"_target"];
NSLog(@"%@",targetofMyGes );//you can see reference for target object

谢谢neilco – 他的回答有助于创建解决方案.

注意:对象targetofMyGes的确切类需要自己定义.认情况下,它id – 适用于任何对象类.

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...