Note that there are some explanatory texts on larger screens.

plurals
  1. POmultiple ViewControllers (containerView? childView? instance of viewController?)
    text
    copied!<p>I need to have a new view(w/ ViewController) added over the top of another. The user interacts with this new view for a while, and then I want to remove it. In an older version of Xcode I was able to add it as a subview. I now get an EXC_BAD_ACCESS error.</p> <p>I don't want the added view as a modal. I need to see the original background through the added view. I've read a lot about the new custom containerViews, addChildView, &amp; presentView. I can't see that any of these are the clear answer.</p> <p>Here's the old code that worked before - Action in the main ViewController:</p> <pre><code>-(IBAction)showWhiteView:(id)sender { WhiteViewController *whiteView = [[WhiteViewController alloc] initWithNibName:@"WhiteViewController" bundle:nil]; [self.view addSubview:whiteView.view]; } </code></pre> <p>Action in the added view to remove it:</p> <pre><code>-(IBAction)removeView:(id)sender { [self.view removeFromSuperview]; } </code></pre> <p>Thanks for your help.</p> <p>Maybe a VISUAL EXAMPLE will help explain - Let's say the main view is an ocean, with animated waves and clouds moving controlled by MainView Controller. The user taps something and a I want to add a boat(WhiteView) to the main view. I want the user to interact with boat: tap here the sail opens, tap there the anchor drops, etc. (needing the methods of the WhiteViewController) Eventually I want to remove the boat from the ocean.</p> <p>Thanks Tim - New code added:</p> <pre><code>-(IBAction)showWhiteView:(id)sender { WhiteViewController *whiteView = [[WhiteViewController alloc] initWithNibName:@"WhiteViewController" bundle:nil]; [self addChildViewController:whiteView]; [whiteView didMoveToParentViewController:self]; [self.view addSubview:whiteView.view]; } </code></pre> <p>and within the WhiteViewController to remove:</p> <pre><code>-(IBAction)removeView:(id)sender { [self.view removeFromSuperview]; [self removeFromParentViewController]; } </code></pre> <p>I look forward to any further suggestions on making this better. Thanks all!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload