문제

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.

도움이 되었습니까?

해결책

UIButton * buttonHit = (UIButton *)[recognizer view];
NSAssert([buttonHit isKindOfClass:[UIButton class]], @"Recognizer must be associated with a UIButton");
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top