I have added a viewcontroller's view as a child view in an another viewcontroller. The child view controller has a tableview. Child view controller can be pushed more than once while click on didSelectRow
to show updated data in same viewcontroller which is working fine. But when I push the child view controller from my parent view the child view changes its frame to original viewcontroller frame and leave the parent view. So I want to make sure that it will always stay in the frame of its parent view and push and pop will occured only inside parent view.
Adding child view:
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Home" bundle:nil];
ChildViewController *vc = [sb instantiateViewControllerWithIdentifier:@"ChildViewController"];
[self addChildViewController:vc];
[vc.view setFrame:self.tableFilters.frame];
[self.viewContainer addSubview:vc.view];
[vc didMoveToParentViewController:self];
Code written in Child viewcontroller's didSelctRow method:
ChildViewController *newMyTableVC = [self.storyboard instantiateViewControllerWithIdentifier:@"ChildViewController"];
newMyTableVC.delegate = self;
[self.tableView reloadData];
[self.navigationController pushViewController:newMyTableVC animated:YES];
Since your child view controller is not embedded in an instance of UINavigationController
self.navigationController
points to its parent's navigation controller. That is why pushing and popping happens in the parent view controller.
To make pushing and popping work in your child view controller you have to embed the child view controller in a UINavigationController
:
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Home" bundle:nil];
ChildViewController *vc = [sb instantiateViewControllerWithIdentifier:@"ChildViewController"];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:vc];
[self addChildViewController:nc];
[nc.view setFrame:self.tableFilters.frame];
[self.viewContainer addSubview:nc.view];
[nc didMoveToParentViewController:self];