我试图改变我的容器视图的内容,基于从TableViewController选择的内容,我不知道该怎么做。
我的storyboard的结构如下所示:
目前,我的容器视图已经嵌入了表格视图,这很好。 现在,从Table View中选择一些内容后,例如Map,我想在容器视图中显示MapViewController并保留页眉和页脚。 我怎样才能做到这一点?
I'm trying to change the content of my container view based on what has been chosen from TableViewController and I'm out of an idea.
The structure in my storyboard looks like this:
Currently, my container view has embed segue with Table View and that's working great. Now after select something from Table View for example Map I want to display MapViewController inside container view and keep my header and footer. How can I do this?
最满意答案
首先将您的容器视图的segue从您的故事板中的DestinationViewController中禁用。 现在根据你以前的tableViewController选择加载你的viewController对象。
//this controller will be change on tableView selection make your own logic here. let controller = storyboard!.instantiateViewController(withIdentifier: "Second") addChildViewController(controller) //Set this value false if you want to set Autolayout programmatically or set it true if you want to handle it with `frame` controller.view.translatesAutoresizingMaskIntoConstraints = false containerView.addSubview(controller.view) controller.didMove(toParentViewController: self)First disable the segue form your container view to a DestinationViewController in your storyboard. Now load your viewController object based on your previous tableViewController selection.
//this controller will be change on tableView selection make your own logic here. let controller = storyboard!.instantiateViewController(withIdentifier: "Second") addChildViewController(controller) //Set this value false if you want to set Autolayout programmatically or set it true if you want to handle it with `frame` controller.view.translatesAutoresizingMaskIntoConstraints = false containerView.addSubview(controller.view) controller.didMove(toParentViewController: self)更多推荐
发布评论