UITableViewController as ChildViewController not calling delegate methods

1.7k views Asked by At

I have a UITableViewController , when I use it as 'initial view controller' ,it works perfect. Now, I am using it as a 'child view controller ' of another View controller, but now when I try to select a row , 'didSelectRow' method is not called while when I long tap on the same row, the 'didSelectRow' method gets called. I had gone through almost every question on UITableviewController on SO but till now I haven't found any solution to this problem.

I am using XCode 6 and following code is used to add it as the child View Controller

[self addChildViewController:vc];
[self.ringtoneView addSubview:vc.view];
[vc didMoveToParentViewController:self];

Any help would be greatly appreciated.

2

There are 2 answers

0
SandeepAggarwal On BEST ANSWER

Finally I managed to solve the problem, thanks to this answer https://stackoverflow.com/a/18159463/3632958

I added a tap gesture recogniser by mistake in the Parent view controller which was preventing the normal selections on table view.

3
Y.Bonafons On

When you call the method

[self addChildViewController:vc];

you just tell to the parents viewcontroller to forward apparence and orientation method like

  • viewWillAppear:
  • viewDidAppear:
  • viewWillDisappear:
  • viewDidDisappear:
  • willRotateToInterfaceOrientation:duration:
  • willAnimateRotationToInterfaceOrientation:duration:
  • didRotateFromInterfaceOrientation:

So I think it's better to create an UITableView and to assign your parents view controller as the tableview's delegate and datasource. So your view controller need to adopt the UITableViewDelegate protocol and the UITableViewDataSource.