Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableViewController as ChildViewController not calling delegate methods

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.

like image 404
SandeepAggarwal Avatar asked Sep 25 '26 17:09

SandeepAggarwal


2 Answers

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.

like image 61
SandeepAggarwal Avatar answered Sep 28 '26 08:09

SandeepAggarwal


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.

like image 31
Y.Bonafons Avatar answered Sep 28 '26 07:09

Y.Bonafons



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!