On IOS 5.1 I have added a container view to a viewcontroller on storyboard. I want to connect that container view via IBOutlet, so I can manage it easily on IB.
I have tried to use a regular UIView:
@property (nonatomic,weak) IBOutlet UIView *leftView; //connected this to container view on interface builder
then, if I use this, it doesn’t work
[self.leftView addSubview:tableVC.view];
If I add a childview controller programmatically it works but it covers full screen of course.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
UIStoryboard* sb = [UIStoryboard storyboardWithName:@"MainStoryboard"
bundle:nil];
UITableViewController *tableVC = [sb instantiateViewControllerWithIdentifier:@"LogMasterViewController"];
[self.view addSubview:tableVC.view];
[self addChildViewController:tableVC];
[tableVC didMoveToParentViewController:self];
}
How can I connect container view to child view controller?
I just tested the following and it works fine:
A couple of thoughts:
If your
LogMasterViewControlleris not aUITableViewController, but rather a view controller with aUITableViewon it, you might want to make sure that you don’t have autolayout or autosizing constraints on that tableview that make it resize the tableview to something that you can no longer see.You might want to run the app, pause it after the app has finished presenting the screen (I put a breakpoint in
viewDidAppear… anything after that point should also work too, but don’t doviewDidLoadorviewWillAppear) with theLogMasterViewControllerinself.leftViewand then type the following command in the debugger console:You might want to give your
leftViewand the main view ofLogMasterViewControllerunique tag numbers so you can more easily decipher the output. Anyway, use thisrecursiveDescriptionto identify whether the table view has been presented, but simply in a fashion so you cannot see the table, or whether it’s not added at all. You can also confirm that yourleftView(with its uniquetagnumber, if you gave it one) is there, too.In this example, I gave my main view of my root controller a
tagof “1”,leftViewhas atagof “2”, and the main view ofLogMasterViewControllerhas atagof “3”. In this case, these show up as the second, third, and fourth lines of my output (and I also see myUITableViewCellslisted below).