Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 509
Ashok Avatar asked Nov 27 '13 11:11

Ashok


2 Answers

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.

like image 189
Ruslan Soldatenko Avatar answered Nov 02 '22 14:11

Ruslan Soldatenko


UIGestureRecognizer internally maintains an array of targets. There is no public access to this array.

like image 24
neilco Avatar answered Nov 02 '22 15:11

neilco