2

See the following setup in my Storyboard:

enter image description here

I've got two container views in the first view controller, one for the main view that displays posts, and the other for a menu that the posts view slides out to reveal.

I'd like the menu bar to slide away like described here, which I have working but without the navigation bar. I've tried using Editor > Embed in Navigation Controller to both the view controller that contains the children (which worked, but when the menu slid out it still showed for the menu which doesn't look as intended) and when I just do it for the posts view controller it crashes with this error:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationController setContainingViewController:]: unrecognized selector sent to instance 0x8e81c60'

Does anyone know how to accomplish this effect?

Community
  • 1
  • 1

1 Answers1

0

I assume this post is related to this one by Doug Smith, Why does hiding my status bar completely break my simple animation?. Your problem doesn't have anything to do with only one of the controllers being embedded in a navigation controller. It crashes, because you're trying to call setContainingViewController on a UINavigationController instead of the PostsViewController, which was (before you added the navigation controller) the destinationViewController of the embed segue. Since the navigation controller is now the destinationViewController, you need to change the code in prepareForSegue to this:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"Posts"]) {
        UINavigationController *nav = (UINavigationController *)segue.destinationViewController;
        PostsViewController *postsViewController = (PostsViewController *)nav.topViewController;
        postsViewController.containingViewController = self;
    }
    if ([segue.identifier isEqualToString:@"Menu"]) {
        MenuViewController *menuViewController = (MenuViewController *)segue.destinationViewController;
        menuViewController.containingViewController = self;
    }
}
Community
  • 1
  • 1
rdelmar
  • 102,832
  • 11
  • 203
  • 218
  • Ah ha! Doug as well as a few others are part of a software group, so it's indeed related. Good eye!:) –  Dec 13 '13 at 05:18