Question

I want to assign a result of swiping to a button, so I can proceed with further actions. I found a straightforward way of doing it, but unfortunately not very elegant and throwing a warning.

Example: assume recognizer is an instance of UISwipeGestureRecognizer. Then...

UIButton *buttonHit = [recognizer view];

It works, but results in

Incompatible pointer types initializing 'UIButton *' with an expression of type 'UIView *'

Any better way of achieving the same? I didn't find any UIButton special constructor. I must be missing something simple. Thanks a lot.

Was it helpful?

Solution

UIButton * buttonHit = (UIButton *)[recognizer view];
NSAssert([buttonHit isKindOfClass:[UIButton class]], @"Recognizer must be associated with a UIButton");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top