在容器视图中使用UITableView进行表单-如何访问表单字段? [英] Using UITableView inside Container view for forms - how do I access the form fields?

查看:42
本文介绍了在容器视图中使用UITableView进行表单-如何访问表单字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在情节提要板中使用表视图来构建表单,但是当表位于容器内部时,我想不出一种简单的方法来访问表单字段.

I'm experimenting with using table views inside a Storyboard to build forms, but I can't figure out a simple way to access the form fields when the table is inside a container.

这就是我所拥有的:

  • 带有容器视图的自定义视图控制器(LoginController),其中包含表单
  • 嵌入在容器中的静态UITableViewController
  • UITableViewController单元格内的
  • 字段(电子邮件,密码等)
  • a custom view controller (LoginController) with a Container View where the form goes
  • a static UITableViewController embedded in the Container
  • fields (email, password, etc.) inside cells in the UITableViewController

我的问题是:从LoginController访问电子邮件和密码字段的值的最简单方法是什么?似乎没有任何方法可以将字段链接到LoginController中的IBOutlets.我可以为我构建的每种表单制作一个自定义的表格视图控制器,或者使用segue做一些事情,但这变得太复杂了.有什么办法可以将所有内容保留在情节提要中?

My question is: what's the simplest way to access the value of the email and password fields from LoginController? There doesn't seem to be any way to link the fields to IBOutlets in the LoginController. I could make a custom table view controller for every form I build, or do something with the segue, but that's getting too complicated. Is there any way to keep everything in the storyboard?

推荐答案

如果要使用表视图,则有两种选择.您可以使用动态原型而不是静态表,因此可以将表视图直接添加到登录控制器(并根据需要调整其大小).或者,您可以像使用嵌入式表视图控制器一样在问题中进行操作.在这种情况下,您可以在prepareForSegue中使登录控制器成为表视图控制器的委托.实例化登录控制器时将调用该方法,因此您可以在此处将自己设置为委托.然后,您需要在表视图控制器中定义一个委托协议,以将您收集的数据发送回委托.这样,就无法在情节提要中设置所有内容(就直接插座而言,因为您无法跨控制器设置插座).

If you want a table view, then you have two choices. You can use dynamic prototypes instead of a static table, so you can add a table view directly to the login controller (and size it how you want). Or, you can do it like you are doing in your question with an embedded table view controller. In that case, you could make the login controller the delegate of the table view controller in prepareForSegue. That method would be called when the login controller is instantiated, so you can set yourself as delegate there. You would then need to define a delegate protocol in the table view controller to send the data you collect back to the delegate. Doing it this way, there's no way to set up everything in the storyboard (in terms of direct outlets, because you can't set up outlets across controllers).

这篇关于在容器视图中使用UITableView进行表单-如何访问表单字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆