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.
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, & presentView. I can't see that any of these are the clear answer.
Here's the old code that worked before - Action in the main ViewController:
-(IBAction)showWhiteView:(id)sender
{
WhiteViewController *whiteView = [[WhiteViewController alloc] initWithNibName:@"WhiteViewController" bundle:nil];
[self.view addSubview:whiteView.view];
}
Action in the added view to remove it:
-(IBAction)removeView:(id)sender
{
[self.view removeFromSuperview];
}
Thanks for your help.
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.
Thanks Tim - New code added:
-(IBAction)showWhiteView:(id)sender
{ WhiteViewController *whiteView = [[WhiteViewController alloc] initWithNibName:@"WhiteViewController" bundle:nil];
[self addChildViewController:whiteView];
[whiteView didMoveToParentViewController:self];
[self.view addSubview:whiteView.view]; }
and within the WhiteViewController to remove:
-(IBAction)removeView:(id)sender
{ [self.view removeFromSuperview];
[self removeFromParentViewController]; }
I look forward to any further suggestions on making this better. Thanks all!