Hide or temporarily remove a child ViewController from a parentViewController?

Adam picture Adam · Aug 26, 2013 · Viewed 7.2k times · Source

(asking and self-answering, since I found no hits on Google, but managed to find a solution in the end by trial and error)

With iOS 5 and 6, Apple added some ugly hacks to make InterfaceBuilder support "embedded" viewcontrollers. They didn't document how those work, they only give code-level examples, and they only cover a limited subset of cases.

In particular, I want to have an embedded viewcontroller that is sometimes hidden - but if you try the obvious approach it doesn't work (you get a white rectangle left behind):

childViewController.view.hidden = TRUE;

Answer

JonahGabriel picture JonahGabriel · Aug 27, 2013

Why don't you just create an IBOutlet to your container view and do

self.containerView.hidden = YES;