简体   繁体   English

如何将数据从UIViewController传递到嵌入在该UIViewController上的容器中的UITableViewController?

[英]How can I pass a data from UIViewController to a UITableViewController that is embedded in a container placed on that UIViewController?

I have an ios app written in swift and there I have a UIViewController with a container on half of the screen. 我有一个用Swift编写的ios应用,那里有一个UIViewController ,在屏幕的一半上有一个容器。 This container has embedded UITableViewController and I want to display there some data that I'm fetching from my webservice. 这个容器内嵌了UITableViewController ,我想在那里显示一些我从Web服务中获取的数据。 The problem is that to fetch the data from web service I need an unique id number that I store in the UIViewController . 问题是要从Web服务中获取数据,我需要一个唯一的ID号,该ID号存储在UIViewController So how can I pass that data from one controller to another? 那么如何将数据从一个控制器传递到另一个控制器?

I have a project on github (written in Objective-C) that does exactly what you want. 在github上有一个项目 (用Objective-C编写),正是您想要的。 It has the horribly unoriginal name "test". 它具有可怕的原始名称“ test”。

It has a master view controller with 2 child view controllers, each of which is a subclass of UITableViewController set up to manage static table views. 它具有一个带2个子视图控制器的主视图控制器,每个子视图控制器都是UITableViewController的子类,该子类设置为管理静态表视图。 (That detail doesn't really matter. It's the method of setting up connections between parent and child view controllers that addresses your question.) (该细节实际上并不重要。它是在父视图视图控制器和子视图控制器之间建立连接的方法,可以解决您的问题。)

The idea is that you set up your child view controller in a container view and link it in with an embed segue. 这个想法是您在容器视图中设置子视图控制器,并将其与嵌入的segue链接。

When you use an embed segue then prepareForSegue fires when the views are loaded. 当您使用嵌入segue时,则在加载视图时会触发prepareForSegue In your prepareForSegue you save a reference to your child view controller(s) if you need to call it/them, and make yourself each child's delegate if you need it to call you . 在你prepareForSegue你一个参考保存到您的子视图控制器(S),如果你需要调用它/他们,并让自己每个孩子的代表,如果你需要来打电话给

The code would be different in Swift but the concept is identical. 代码在Swift中会有所不同,但是概念是相同的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从嵌入在该控制器容器中的uiviewcontroller调用存储在父uiviewcontroller中的方法? - how can I call a method stored in a parent uiviewcontroller from the uiviewcontroller embedded in a container in that controller? 如何从父UIViewController调用嵌入在容器中的UIViewController内部的方法? - How can I call a method that is inside a UIViewController embedded in a container from a parent UIViewController? 当嵌入到UIViewController中的容器中时,切断UITableViewController - Cut off UITableViewController when embedded into a Container in a UIViewController 我如何将数据从UIViewController传递到SWRevealViewController - How can i pass data from UIViewController to SWRevealViewController 为什么我不能从嵌入式UITableViewController调用存储在父UIViewController中的方法? - Why I can't call a method stored in parent UIViewController from embedded UITableViewController? UITableViewController单元格模式将数据传递到下一个UIViewController - UITableViewController cell modal pass data to next UIViewController 我可以让UITableViewController和UIViewController从同一个类继承吗? - Can I have UITableViewController and UIViewController inherit from the same class? 当UITableViewController嵌入到UIViewController的Container中时,额外的表格单元格 - Extra table cells when UITableViewController is embedded into a Container in a UIViewController UIViewController无法查看UITableViewController - UIViewController can not view UITableViewController 如何在Swift中使用另一个UIViewController将容器覆盖父UIViewController中的UI元素? - How can I cover a UI element from the parent UIViewController by a container with another UIViewController in Swift?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM