Tuesday, January 17, 2012

iPhone | Getting touch event in UIScrollView Or scrollable UITableView

Unable to get tap event in scrolling view or scrollable table view?

hmm... Really a bad situation.. by the way here is the solution :)

Put this in viewDidLoad method :

(YOUR_SCROLL_VIEW may be UIScrollView or scrollable UITableView)

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapGestureCaptured:)];

[YOUR_SCROLL_VIEW addGestureRecognizer:singleTap];

and you will get the touches with :

- (void)singleTapGestureCaptured:(UITapGestureRecognizer *)gesture {

CGPoint touchPoint=[gesture locationInView:YOUR_SCROLL_VIEW];

NSLog(@"Touch point coordinates are : %f - %f", touchPoint.x , touchPoint.y );

}

this worked for me, hope this helps to save your time!