6
votes

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.

2
Double check to make sure you don't use – tableView:didDeselectRowAtIndexPath: instead of didSelectRowAtIndexPathVig
@Vig Yup, after the first Tap my implementation of didSelectRowAtIndexPath is been called.6rod9
Why are you embedding non-scrollable table view in scroll view in the first place?sha
Does anything happen when you tap on a cell? Pushing a ViewController or something?beeef
@sha Because I get use of the functionality and look of the UITableView. For example Inserting and Deleting rows dynamically without a UITableView would be very difficult to implement.6rod9

2 Answers

2
votes

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.

0
votes

Please disable scrolling of your table view and check the datasource and delegate are connected to your table view. If not follow the bellow code

@interface myClass ()<UITableViewDataSource, UITableViewDelegate>

- (void)viewDidLoad {
    [super viewDidLoad];

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