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