3

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.

SandeepAggarwal
  • 1,273
  • 3
  • 14
  • 38

2 Answers2

2

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.

Community
  • 1
  • 1
SandeepAggarwal
  • 1,273
  • 3
  • 14
  • 38
1

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.

Y.Bonafons
  • 2,329
  • 13
  • 20
  • This would work, but I dont want to go this way, the question is why UITableViewController is not working as intended when added as childViewController. – SandeepAggarwal Nov 29 '14 at 17:12
  • Ok then I think you need to put [self addChildViewController:vc]; and [self.ringtoneView addSubview:vc.view]; in the viewdidAppear method of your parents viewcontroller. [vc didMoveToParentViewController:self]; is not useful. – Y.Bonafons Nov 29 '14 at 18:07
  • I am not adding the childViewController on viewDidLoad, but dynamically at run time upon some condition is satisfied – SandeepAggarwal Nov 29 '14 at 18:10