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

标签 ios iphone swift uitableview ios9

我目前正在尝试编写表行删除代码(来自核心数据)。我正在使用一个名为“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!)
    }
}
<小时/>

该方法非常简单:我相信这是主详细信息模板中使用的方法。区别在于自定义类。

有什么想法吗?

最佳答案

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

关于ios - 使用自定义类时删除行的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36725192/

相关文章:

ios - SWIFT 线程 1 : EXC Bad instruction XCODE IOS

swift - 在swift中向闭包内的变量添加值

ios - 在 stringByReplacingOccurrencesOfString 中替换的字符串数

IOS 如何获取 IDFA?不导入 Adsupport.framework

ios - 如何通过跳过选项卡栏 Controller 将数据从 VC 传递到另一个

ios - 任何人都知道如何在 QueryForTable 中缩小此查询(使用 Parse.com)

iphone - UILabel 中的可点击词

ios - 嵌套推送动画会导致导航栏损坏 PUSH POP PUSH

iphone - 如何在 iPhone 中获取两天之间的差异

swift - 如何在 Swift 中存储对整数的引用