根据tableview中的选择将视图控制器嵌入到容器视图中(Embed view controller inside container view based on selection from ta

编程入门 行业动态 更新时间:2024-10-25 21:28:17
根据tableview中的选择将视图控制器嵌入到容器视图中(Embed view controller inside container view based on selection from tableview)

我试图改变我的容器视图的内容,基于从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)

更多推荐

本文发布于:2023-07-29 14:13:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1316793.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   控制器   容器   Embed   tableview

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!