【问题标题】:TableView CoreData error: Assertion failure in ... in SwiftTableView CoreData 错误:Swift 中 ... 中的断言失败
【发布时间】:2014-11-21 13:04:32
【问题描述】:

我在我的应用中实现了 Core Data。 如果我运行它,我会收到以下错误: 2014-11-21 13:29:28.400 MyApp[2630:37096] *** Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-3318.16.14/UITableView.m:6116

我不知道我做错了什么(我还在学习 swift)。

这是发生错误的函数:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    var cell:MyTableViewCell = tableViewNotes.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as MyTableViewCell
    cell.textLabel.text = "\(daten[indexPath.row].aufgabe)"

    return cell
}

以及发生错误的行:

var cell:MyTableViewCell = tableViewNotes.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as MyTableViewCell

【问题讨论】:

    标签: ios uitableview core-data swift


    【解决方案1】:
    used tabeView in place of tableViewNotes
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    
        var cell:MyTableViewCell = tabeView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as MyTableViewCell
        cell.textLabel.text = "\(daten[indexPath.row].aufgabe)"
    
        return cell
    }
    

    让我知道它是否有效。

    【讨论】:

    • 感谢您的快速答复!现在我在 CoreData 库中获得了一个断点。但它似乎工作。我更进一步。
    【解决方案2】:

    您是否在情节提要中使用自定义单元格标识符名称“单元格”? 如果不。请将此“单元格”提供给您的自定义单元格标识符。我希望它会起作用

    【讨论】:

    • 非常感谢您的回答。我没有使用故事板。如何以编程方式执行此操作?
    • 那么您必须在 MyTableViewCell 的 xib 子类中使用标识符“Cell”的单元格。因为方法 dequeueReusableCellWithIdentifier(identifier: String, forIndexPath indexPath: NSIndexPath) -> AnyObject // 较新的 dequeue 方法保证单元格被返回并正确调整大小,假设标识符已注册,否则您可以使用 var cell : MyTableViewCell! = tableView.dequeueReusableCellWithIdentifier("Cell") 作为 MyTableViewCell? if cell == nil { cell = UITableViewCell(style: .Default, reuseIdentifier: "Cell") }
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-28
    • 2015-05-21
    • 1970-01-01
    • 1970-01-01
    • 2021-10-11
    • 1970-01-01
    相关资源
    最近更新 更多