2016-04-19 5 views
0

現在、(コアデータから)テーブル行の削除をコード化しようとしています。私は "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!) 
    } 
} 

このメソッドはかなりシンプルです。私はそれがマスターディテールテンプレートで使用されていると信じています。違いは、カスタムクラスです。

アイデア?

答えて

0

tableView.cellForRowAtIndexPath(indexPath!)UITableViewCellを返すようです。メソッドに渡す前に、おそらくas! CustomTableViewCellでカスタムタイプにキャストする必要があります。

+0

それが既にある: 'FUNCのにtableView(のtableView:のUITableView、cellForRowAtIndexPath indexPath:NSIndexPath) - >のUITableViewCell { はセル= tableView.dequeueReusableCellWithIdentifierてみましょう( "セル"、forIndexPath:indexPath)など! CustomTableViewCell letオブジェクト= self.fetchedResultsController.objectAtIndexPath(indexPath)を! NSManagedObject self.configureCell(セル、withObject:オブジェクト) 戻りセル } ' –

+0

上記のエラーが発生している上記の更新行では、 –

+0

Duhを意味します。一定。問題は実際に問題の行にあった: 'self.configureCell(tableView.cellForRowAtIndexPath(indexPath!)!as!CustomTableViewCell Custom、withObject:anObject as!NSManagedObject)//これはオフェンドケースです' –

関連する問題