无法使用Realm对象填充TableView

时间:2019-04-20 09:07:03

标签: ios swift uitableview realm

我正在使用Realm,并且无法使用Realm对象填充我的表视图。如果我为textLabel分配了一个简单的String,但没有realm对象,则可以使用它。

它适用于对象Deck,该对象包含抽认卡的领域列表

enter image description here

但是,如果您去上一门课程,它不会显示抽认卡。如前所述,如果我在cellForRowAt中分配一个计划字符串,那么它将起作用。

enter image description here

如果我从cellForRowAt函数打印Realm,它将显示正确的值

enter image description here

功能

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "FlashcardCell", for: indexPath)

    let flashcard = flashcards[indexPath.row]

    print(flashcard)

    cell.textLabel?.text = "hi"
    cell.detailTextLabel?.text = flashcard.name

    return cell
}

我的模特

class Deck: Object {

    let flashcards = List<NewFlashcard>()

    @objc dynamic var name: String?
    @objc dynamic var color: String?
}

1 个答案:

答案 0 :(得分:0)

问题是我忘记了dynamic

class NewFlashcard: Object {

    @objc dynamic var name: String?

}
相关问题