iosobjective-cuitableviewuigesturerecognizer

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.


Solution

  • 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.