1

和其他许多人一样,我想在 Eureka 中实现一个自定义行。

因此,我按照教程进行操作,甚至查看了 Eureka-Community 提供的一些示例。

这是我的代码:

open class EditorTextCell: Cell<Field>, CellType {
@IBOutlet weak var questionLabel: UILabel!
@IBOutlet weak var questionField: UITextField!
// TODO 
}

该行是:

public final class EditorTextRow: Row<EditorTextCell>, RowType {
    required public init(tag: String?) {
        super.init(tag: tag)
        cellProvider = CellProvider<EditorTextCell>(nibName: "EditorTextCell")
    }
}

我的数据结构很简单:

public class Field: Object {
    dynamic var question = ""
    dynamic var mandatory = false
}

据我了解,我需要一个数据结构来保存我的自定义行将在用户交互后保存/生成的数据。这个自定义数据结构在我的例子中是一个 Realm 对象,所以我想 - 为什么不重用它呢?之后,应该将自定义数据结构传递到Cell<MyDataStructure>我正在定义的自定义单元格中。自定义行只是加载我的 nib 并声明使用哪个单元格Row<MyCustomCell>。就这样。正确的?

我在尝试实例化我的自定义行(如form.last! <<< EditorTextCell().

我阅读了官方文档,上面写着: Custom rows need to subclass Row<CellType> and conform to RowType protocol. Custom cells need to subclass Cell<ValueType> and conform to CellType protocol.- 这就是我正在做的事情。我还在 stackoverflow 上找到了链接,它提供了一些我已经在遵循的建议。我看了一下这个,这是一个官方的例子。我基本上只是写下了他们做了什么,但它不起作用。

为什么?

我看到的唯一区别是他们写了一个单独的下划线类型Row<MyCustomCell>并做了一些我不明白的事情。我不明白为什么这是必要的,如果他们 github 上的官方文档说它足以继承和采用Row<MyCustomCell>and RowType

4

1 回答 1

1

我认为您的错误是您必须在代码中替换EditorTextCellEditorTextRow

form.last! <<< EditorTextRow()
于 2017-02-15T02:47:26.377 回答