swift - 自定义 UITableView 内的 UITextField 在 Swift 中为零

标签 swift uitableview uitextfield

我当前的项目中有一个 UITableView。每个单元格都是自定义类 DecisionItem 的对象,该类实现了 UITableViewCell。每个 DecisionItems 内部应该有一个名为“descriptionBox”的 UITextField。然而,每次我运行这个应用程序时,descriptionBox 总是显示为零。这是为什么?

这是控制台中显示的内容,如您所见,descriptionBox 为 nil:

enter image description here

这是我的原型(prototype)单元:

prototypecells

运行应用程序时,我的单元格显示完全空白:

enter image description here

这些是我已确保完成的事情:

  1. 是的,DecisionItem 有一个名为descriptionBox 的IBOutlet 变量,该变量连接到原型(prototype)单元中的UITextField。

enter image description here

  • 是的,我将原型(prototype)单元的类设置为自定义类 DecisionItem
  • enter image description here

  • 是的,我将单元格转换为 cellForRowAt 函数中的 DecisionItem
  • enter image description here

  • 是的,我的重用标识符都是正确的。
  • 什么可能导致此错误?

    最佳答案

    在左侧场景层次结构的 Storyboard 中,右键单击 DecisionItem 单元格并将鼠标悬停在描述框上,以确保它突出显示 Storyboard 中的正确文本字段。如果您看到黄色警告标志,请单击 X 并重新链接。

    关于swift - 自定义 UITableView 内的 UITextField 在 Swift 中为零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53806381/

    相关文章:

    ios - 让 UITextField 更改 Webview URL

    ios - 如何为 UITableView 中的部分添加标题?

    ios - UITable,如何在 Swift IOS 中将委托(delegate)分配给 UITable

    ios - 使用 UITextView 时关闭键盘的正确方法是什么?

    ios - Swift - 混合抽象和具体方法

    ios - 具有自定义逻辑的可重用 UITableViewCell

    ios - 如何将文本字段限制为仅有效小数?

    ios - 个人资料图片在 UITableViewCell 中被截断

    ios - Localizable.strings 不翻译短语

    ios - 在 Swift 中水平滚动图像(如 Youtube 应用程序)