PDA

View Full Version : iOS 5 UIViewController Containment Issue




isthisonetaken
Feb 20, 2012, 04:36 PM
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?

Thanks



seepel
Feb 20, 2012, 08:44 PM
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?

Thanks

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.

isthisonetaken
Feb 20, 2012, 11:18 PM
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.

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?

jnoxx
Feb 21, 2012, 02:34 AM
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?

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 :)