iOS 5 UIViewController Containment Issue

Discussion in 'iOS Programming' started by isthisonetaken, Feb 20, 2012.

  1. isthisonetaken macrumors regular

    Jun 29, 2006
    Hey GUys,

    so I'm trying to use iOS 5's new API's for containing children view controllers in a parent view. I got it working for simply UIViewControllers but I'm having some issues with a UITableViewController to show up properly.

    In my storyboard I have a UIViewController which is my parent view controller. It has a UIView with an outlet hooked up where I want the child UITableViewController to go. I also have a separate scene which is a UITableViewController embedded in a navigation controller. In my viewDidLoad method in the Parent I call this code:

        ChargesTableViewController *chargesController = [storyboard instantiateViewControllerWithIdentifier:@"ChargesScene"];
        chargesController.view.frame = self.chargesView.bounds;
        self.chargesView.layer.cornerRadius = 15.0;
        self.chargesView.layer.masksToBounds = YES;
        [self.chargesView addSubview:chargesController.view];
        [chargesController didMoveToParentViewController:self];
        [self addChildViewController:chargesController];
    It shows the table view (currently empty) and can be scrolled, but it doesn't show me the Navigation Bar which has an Add button on it for adding new charges.

    The functionality I'm looking to accomplish is to display a bunch of charges in the table view and somehow allow the user to add a new charge. I can't add a UIToolBar to the UITableViewController, so I thought if I embedded the view controller in a nav controller, it would let me see and use the nab bar, but it's not...

    Any ideas how to either fix this or add the functionality I'm looking for?

  2. seepel macrumors 6502


    Dec 22, 2009
    To do what you want you'll have to add the NavigationController's view rather than the ChargesController's. I suspect this might get tricky though, I seem to remember having problems when I tried to do something like this in the path. Th UInavigationController kind of expects to be in some sort of hierarchy of controllers, and might not play nicely by having its view shoved into another view.
  3. isthisonetaken thread starter macrumors regular

    Jun 29, 2006
    The only reason I had the nab bar was to be able to have an 'Add' button. Is there some other way to allow the user to Add new content to the table if I can't have access to a nab bar or tool bar? Can I have a button in the parent view and pass a message onto the child view when it is clicked?
  4. jnoxx macrumors 65816


    Dec 29, 2010
    Aartselaar // Antwerp // Belgium
    Only responding to your last post here.
    You don't need the nav bar if you're not using it's functionality, you can also just add a Tabbar, and put buttons on there.
    If you don't have acces, you should maybe do it like you described in your last sentence, have a button in your parent view controller, and send a delegate message, or send it via NSNotificationCenter, and pass the object with it..
    There are alot of possibilities :)

Share This Page