UITableView (inside UIScrollView) didSelectRowAtIndexPath: not called on first click

I have a scrollable UITableViewinside UIScrollView. And I had a problem: when I touch the line, the callback is didSelectRowAtIndexPath:not called on the first press, but it works after the first press.

A few considerations:

  • After the first click, viewing the table works fine, each answer works in each cell.
  • This happens immediately after scrolling through the UIScrollView. If I do not scroll through the UIScrollView, this will never happen.
  • I overtook UIScrollView touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view, and the event passes here, viewefficiently UITableViewCellContentView.

I just don’t know why the event was not sent for UITableViewthe first time, and for its next actions.

+4
source share
2 answers

If you have UIScrollViewone that contains vertical content and UITableViewas part of this content, you should at least disable scrolling on UITableView- otherwise it confuses the user when he will scroll yours mainViewand when tableView, and also confusing the framework, because it is unclear where to send parchment gestures.

Generally, you should avoid placing table views inside scrollViewsunless you really know what you are doing.

+1
source

, .

@interface myClass ()<UITableViewDataSource, UITableViewDelegate>

- (void)viewDidLoad {
    [super viewDidLoad];

    self.myTableView.scrollEnabled = NO;
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
}
0

All Articles