Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView (inside UIScrollView) didSelectRowAtIndexPath: not being called on first tap

I have a non scrollable UITableView inside an UIScrollView. And I'm having the problem that when I touch a row, the callback didSelectRowAtIndexPath: is not being called on the first tap, but after the first tap everithing works.

A few considerations:

  • After the first tap, the table view works normally, every tap works in every cell.
  • This happens just after I scroll the UIScrollView. If I don't scroll the UIScrollView, this never happens.
  • I have overriden the UIScrollView's touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view and the event does pass throw here, the view is a UITableViewCellContentView effectively.

I just don't know why the event is not been sent to the UITableView on the first time, and on the following ones it does.

like image 209
6rod9 Avatar asked Nov 21 '14 19:11

6rod9


1 Answers

If you have UIScrollView that contains vertical content and UITableView as part of this content, you must at least disable scrolling on UITableView - otherwise it's confusing for the user when he will scroll your mainView and when tableView, and also confusing for the framework because it's not clear where to send panning gestures.

As a rule of thumb - you should avoid putting table views inside scrollViews, unless you really know what you're doing.

like image 187
sha Avatar answered Nov 10 '22 01:11

sha