iOS Tap Gesture in a UIScrollview
I have a RootViewController
& it's associated nib
or xib
file. This nib
is loaded as the app starts. This nib
file contains a UIScrollView
in this scrollview I put another custom generated nib
- newNib.xib
file.
In this newNib.xib
I have made changes in interface builder to respond to RootViewController
i.e. Custom Class - RootViewController
. Then I linked some UIView objects that I created in RootViewController
. All fine so far...
I have defined some tapGestureRecognisers
in RootViewController
on the UIViews
defined in newNib.xib
but they are not responding to the tap events. Tap Events i defined in RootViewController
like this -
UITapGestureRecognizer *messagesTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(messagesBucketTap:)];
[mess开发者_运维百科agesTap setNumberOfTapsRequired:1];
[messagesTap setNumberOfTouchesRequired:2];
[self.messagesSnippet addGestureRecognizer:messagesTap];
[messagesTap release];
here self.messagesSnippet
is present in newNib.xib
Also I load the xib
in RootViewController
like so -
[[NSBundle mainBundle] loadNibNamed:@"newNib" owner:self options:nil];
But still I dont get the tapGesture to the selector (messagesBucketTap). What am i doing wrong?
The most likely cause is that you forgot to set the delegate of the tap gesture recognizer e.g. [messagesTap setDelegate:self]
.
Assuming -messagesBucketTap:
is declared in the same class, Change your code to:
UITapGestureRecognizer *messagesTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(messagesBucketTap:)];
[messagesTap setDelegate:self];
[messagesTap setNumberOfTapsRequired:1];
[messagesTap setNumberOfTouchesRequired:2];
[self.messagesSnippet addGestureRecognizer:messagesTap];
[messagesTap release];
If this doesn't work, check what Jamie said, and make sure you are declaring:
- (void)messagesBucketTap:(UITapGestureRecognizer *)gestureRecognizer;
and not
- (void)messagesBucketTap;
Also, are you tapping once with two fingers? Lastly, ensure that that userInteractionEnabled
is YES on the UIView's and that exclusiveTouch
is NO on the UIScrollView
精彩评论