سؤال

I want to use a tap gesture recognizer to select an object (a UITextView in my case here). When the object is tapped the "recognizer.view" will return what I think is the object being tapped. Below is what I get if I LOG the recognizer.view.

<UITextView: 0xf67afc0; frame = (155.5 119.5; 100 100); text = 'string'; clipsToBounds = YES; tag = 1; layer = <CALayer: 0xf67b1f0>; 

I assume that I want to take the first value here: UITextView: 0xf67afc0; and apply that to a UITextView ivar. I set one up like so

UITextView *selectedTextView;

But when I try to assign recognizer.view to this ivar, I get an error: ! Incompatible pointer types assigning to "UITextView" __strong from "UIView". I guess I need to somehow take the first value only UITextView: 0xf67afc0 and assign that to the ivar? How would I do that, or am I barking up the wrong tree here?

هل كانت مفيدة؟

المحلول

You need to downcast the view property on the recognizer to be a UITextView rather than a UIView.

UITextView *selectedTextView = (UITextView *)recognizer.view;

Hope this helps, if you have any questions let me know.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top