Evren Bingøl
Evren Bingøl

Reputation: 1725

how to set up a selector from a different UIView object for UITapGestureRecognizer

This should be straight forward but I am having some issues with this. I have an UIView A which has a function A. I create a Selector for function A in UIView A.

SEL littleSelector = @selector(handleTapButton1);

I create UIView B and pass this selector to UIView B constructor and save it in UIView B. I set up UITapGestureRecognizer in UIView B and I assign selector from UIViewA "littleSelector" as its action. I get an exception = unrecognized selector sent to instance. I know selectors are not really function pointers but look up numbers. I also made sure that UIView A is retained.

Any ideas ?

Upvotes: 1

Views: 314

Answers (1)

Wain
Wain

Reputation: 119041

A selector needs to be paired with an appropriate target. If you supply a selector for A and a target instance of B you will have this kind of issue. You need to set the target properly to A so the method represented by the selector is called on the right class instance.

Upvotes: 1

Related Questions