【问题标题】:FirebaseUI table view crashes with 'Invalid update: invalid number of rows in section 0FirebaseUI 表视图因“无效更新:第 0 节中的无效行数而崩溃”
【发布时间】:2017-09-28 04:22:00
【问题描述】:

我在选项卡控制器中有 3 个表视图,所有这些视图都像这样填充:

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    self.dataSource = self.notesTableView.bind(to: getQuery()) { tableView, indexPath, snap in

        let cell = self.notesTableView.dequeueReusableCell(withIdentifier: "cellident", for: indexPath)
        let customCell = cell as! TextCell
        self.notesTableView.dataSource = self.dataSource
        self.notesTableView.delegate = self

        if let note = snap.childSnapshot(forPath: "note").value as! String? {
            customCell.notesLabel.text = note
        } else {
            customCell.notesLabel.text = "Undefined"
        }

        return cell
    }
}

当我在手机上运行应用程序并在选项卡之间切换时,在某些时候我总是遇到这个异常:

'NSInternalInconsistencyException',原因:'无效更新:第 0 节中的行数无效。

此外,控制台显示了这一点,但我不确定如何解释:

*** -[UITableView _endCellAnimationsWithContext:] 中的断言失败,/BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3600.7.47/UITableView.m:1737

我的问题是,如果有人知道这个与 FirebaseUI 相关的异常的原因可能是什么。我的猜测是它与填充表格有关。

【问题讨论】:

  • 你的tableView(_:numberOfRowsInSection:)方法的内容是什么样的?
  • @ToddKerpelman 我没有那种方法。我认为这应该包含在 FirebaseUI 库中。

标签: ios swift firebase firebase-realtime-database firebaseui


【解决方案1】:

viewWillDisappear 中设置self.dataSource = nil

所以,请不要错误地更新dataSource

从这个问题 here

根据我的经验,最安全的方法是在viewWillDisappear 设置self.dataSource.unbind()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-28
    • 1970-01-01
    • 1970-01-01
    • 2013-07-28
    • 1970-01-01
    • 2019-10-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多