UITapGestureRecognizer not sending actions to self?

I'm trying to add a UITapGestureRecognizer to a custom view (called 'display') and I am unable to make the receiver send the action to 'self' (an instance of 'OSPPanel'). I am adding the UITapGestureRecognizer like this:


let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: "viewSelected:")

let pressType = UIPressType.Select

tapGestureRecognizer.allowedPressTypes = [NSNumber(integer: pressType.rawValue)];

display!.addGestureRecognizer(tapGestureRecognizer)

print(tapGestureRecognizer)


and this appears on the console:


<UITapGestureRecognizer: 0x150057560; state = Possible; view = <Second_tvOS_app.DisplayRectangle 0x1501178d0>; target= <(action=viewSelected:, target=<Second_tvOS_app.OSPPanel 0x1501018d0>)>>


which looks good but the action does not fire. I added this line to the end of the App delegate:

print(UIScreen.mainScreen().focusedView!.gestureRecognizers![0])

and got this in the console:

<UITapGestureRecognizer: 0x150057560; state = Possible; view = <Second_tvOS_app.DisplayRectangle 0x1501178d0>; target= <(action=viewSelected:, target=<(null) 0x0>)>>


which shows that the target was been wiped but the action is still defined. I've tried putting in explicit references for the target and it seems to work, so if I change the definition to:


let tapGestureRecognizer = UITapGestureRecognizer(target: main!.rootViewController, action: "viewSelected:")

then the console displays:

<UITapGestureRecognizer: 0x12eedf5e0; state = Possible; view = <Second_tvOS_app.DisplayRectangle 0x12eedfa20>; target= <(action=viewSelected:, target=<Second_tvOS_app.ViewController 0x12ed909a0>)>>


in response to both print statements and the action 'viewSelected:', which is also defined in the ViewController, fires as expected. The same happens if I use:


let tapGestureRecognizer = UITapGestureRecognizer(target: display, action: "viewSelected:")


ie the 'viewSelected' method in the object 'display' fires as expected.


So it appears that it is just the use of 'self', which I assumed referred to the object where the UITapGestureRecognizer is defined (an instance of OSPPanel), which is causing a problem. While I can think of workarounds I would prefer the 'viewSelected' method to be in OSPPanel.


Anyone experienced something similar?

UITapGestureRecognizer not sending actions to self?
 
 
Q