Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
444 views
in Technique[技术] by (71.8m points)

objective c - Getting the Action of UIGestureRecognizer in iOS

I have printed a UITableviewCell's gesture in – tableView:didSelectRowAtIndexPath method in NSLog as

<UIScrollViewPanGestureRecognizer: 0x11e92080; state = Possible; cancelsTouchesInView = NO; delaysTouchesEnded = NO; view = <UITableViewCellScrollView 0x11e94bf0>; target= <(action=handlePan:, target=<UITableViewCellScrollView 0x11e94bf0>)>> 

and I have assigned this UIScrollViewPanGestureRecognizer to a UIGestureRecognizer to access the properties of it as follows,

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

I'm able to access all properties of 'myGes' as

 myGes.state;
 myGes.cancelsTouchesInView;
 myGes.delaysTouchesEnded;
 myGes.view;

Except one property named as target.

Is there any possibility to access that property? because i need to perform that action.

Any comments or suggestions would be appreciated.

Thank you in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There is a way to gain access to the property target, but I'm not sure that this method will pass the Apple approval process.

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

Thanks neilco - his answer help create solution.

Note: the exact class of the object targetOfMyGes need to define yourself. By default it id - suitable for any object class.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...