繁体   English   中英

使用自定义类时删除行的问题

[英]Issues with Deleting rows when using a custom class

我目前正在尝试对表格行删除(从Core Data)进行编码。 我正在使用一个名为“ CustomTableViewCell”的自定义类。 一切正常,直到我从以前的应用程序中实现了一个片段,该片段基本上只是添加了滑动删除功能。 我现在收到以下错误:

无法将类型“ UITableViewCell”的值转换为预期的参数类型“ CustomTableViewCell”

令人讨厌的代码如下:


func controller(controller: NSFetchedResultsController, didChangeObject anObject: AnyObject, atIndexPath indexPath: NSIndexPath?, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath?) {
    switch type {
    case .Insert:
        tableView.insertRowsAtIndexPaths([newIndexPath!], withRowAnimation: .Fade)
    case .Delete:
        tableView.deleteRowsAtIndexPaths([indexPath!], withRowAnimation: .Fade)
    case .Update:
        self.configureCell(tableView.cellForRowAtIndexPath(indexPath!)!, withObject: anObject as! NSManagedObject) // THIS IS THE OFFENDING CASE
    case .Move:
        tableView.moveRowAtIndexPath(indexPath!, toIndexPath: newIndexPath!)
    }
}

该方法非常简单:我相信它是Master Detail模板中使用的方法。 区别在于自定义类。

有任何想法吗?

看起来tableView.cellForRowAtIndexPath(indexPath!)返回UITableViewCell 您可能需要使用as! CustomTableViewCell将其转换为自定义类型as! CustomTableViewCell 在将as! CustomTableViewCell传递给方法之前。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM