6

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.

6rod9
  • 1,407
  • 12
  • 29
  • 2
    Double check to make sure you don't use – tableView:didDeselectRowAtIndexPath: instead of didSelectRowAtIndexPath – Vig Nov 21 '14 at 19:46
  • @Vig Yup, after the first Tap my implementation of didSelectRowAtIndexPath is been called. – 6rod9 Nov 21 '14 at 19:49
  • Why are you embedding non-scrollable table view in scroll view in the first place? – sha Nov 22 '14 at 00:31
  • Does anything happen when you tap on a cell? Pushing a ViewController or something? – beeef Nov 22 '14 at 13:20
  • @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 Nov 25 '14 at 13:43
  • @beeef Yes indeed, when I tap the cell a new row is inserted with a UIPickerView in it. – 6rod9 Nov 25 '14 at 13:44
  • @6rod9: My question was more about UIScrollView. What are you using scrollview for? Are you letting user scroll table view around? – sha Nov 25 '14 at 16:16
  • @sha Because I have more content before the UITableView, I have some other UIViews on top of it, and at the bottom the IUTable view. So and the vertical content is too big to fit on the screen, that's why I need the UIScrollView. – 6rod9 Nov 25 '14 at 17:14

2 Answers2

2

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.

Kanan Vora
  • 224
  • 1
  • 9
sha
  • 17,824
  • 5
  • 63
  • 98
  • 1
    The scrolling on the table view is effectively disabled. :/ – 6rod9 Nov 25 '14 at 17:58
  • How exactly it's `effectively` disabled? – sha Nov 25 '14 at 18:04
  • I disabled the scrolling in the storyboard UITableView checkbox "Scrolling Enabled". My guess is that the scroll view still thinks that the first tap is part of the previous scrolling events, but still have no clue why. – 6rod9 Nov 25 '14 at 18:10
  • You need to post some code. What methods did you change in UIScrollview related to touches, what exactly you're doing there etc. – sha Nov 25 '14 at 18:17
  • 1
    I have just overriden `touchesShouldCancelInContentView` to always return `TRUE`, and the delegate method `scrollViewDidScroll`. And in the table view the delegate method `didSelectRowAtIndexPath`, that method is the one that is not called on the first tap. – 6rod9 Nov 25 '14 at 18:49
0

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;
}
Ajith Kumar
  • 1,202
  • 1
  • 10
  • 22