Display whole ViewController within another ViewCo

2019-09-02 12:08发布

问题:

Im writing an application which the main view controller is a UIViewController. It has some icons in a grid and I want to dismiss (sliding down) this grid when one of the icons is clicked. This I've done already. The problem is: when the grid is dismisseed I want another View to come from the top of the screen. This view is in this same root view controller. But I want to display the content of other view controllers in this view. For example: I want this view to show a UINavigationController with a UITableView inside it, so the user can navigate through TableViews.

I'm doing this:

HorariosViewController *horarios = [[HorariosViewController alloc] init];
[vuashView addSubview:horarios.view];

HorariosViewController is a UINavigationViewController. It shows me only a blue NavigationBar and changes like self.navigationItem.title = @"Title" won't work.

Thanks!

回答1:

You can show another view controller's views as subviews but their outlets and actions remain linked to their original view controller unless you write code to make new connections, so self.whatever shouldn't be expected to affect the other view controller's properties.

(Also, if HorariosViewController is a UINavigationController, it shouldn't be created as a UIViewController.)



回答2:

One approach is to have the navigation controller already there, with the icon grid presented modally on top of it. (you can set the view up this way without animations, so the user doesn't see the navigation controller underneath).

Then, when it's time for the grid to go away, it can call dismissModalViewController on itself with animation.