2017-11-23 5 views
0

あなたの助けが必要です! 私はiOS 9のバグで怒っています。 あなたは下記見ることができるように、それはiOSの11初めUITableViewアップデートで失敗する

This is working on iOS 11

にうまくいっている、私は新しいのステータス「ヌーボー」で4個の細胞を持っています。 「新しい」セルをクリックすると、ステータスが「En attente」(「待機中」)に変わります。

iOS 9では、最後のセルまでは問題ありません。最後の「新しい」セルをタップすると、「待機中」に移動せず、「新しい」セクションがまだそこにあります。この後、テーブルビューはもう更新を取得していません、別のviewControllerに変更して、テーブルビューを含むものに戻ったときに正常に戻ります。

私はNSFetchedResultsControllerを使用しています。データはセクションの良い、良い数、セクションによって要素の良い数、良いタイトルです。開始時

終わりに4つのオブジェクト とのタイトル「ヌーボー」との1つのセクションでは、4つのオブジェクト

extension CRDashboardOrdersViewController: UITableViewDataSource { 
    func numberOfSections(in tableView: UITableView) -> Int { 
     print(self.fetchResult?.sections?.count ?? 0) 
     return self.fetchResult?.sections?.count ?? 0 
    } 

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     print(self.fetchResult?.sections?.get(index: section)?.numberOfObjects ?? 0) 
     return self.fetchResult?.sections?.get(index: section)?.numberOfObjects ?? 0 
    } 

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     let cell: CRDashboardOrderTableViewCell = tableView.dequeueReusableCell(withIdentifier: "CRDashboardOrderTableViewCell") as! CRDashboardOrderTableViewCell 
     let order: Order = self.fetchResult.object(at: indexPath) as! Order 

     cell.order = order 

     if let selectedIndexPath = self.selectedIndexPath, selectedIndexPath == indexPath { 
      self.tableView.selectRow(at: selectedIndexPath, animated: false, scrollPosition: .none) 
     } 

     return cell 
    } 
} 

extension CRDashboardOrdersViewController: UITableViewDelegate { 
     func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 
      self.selectedIndexPath = indexPath 
     } 

    func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { 
     print(self.fetchResult?.sections?.get(index: section)?.name ?? "???") 
     return self.fetchResult?.sections?.get(index: section)?.name ?? "???" 
    } 
} 

extension CRDashboardOrdersViewController: NSFetchedResultsControllerDelegate { 
     func controllerWillChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) { 
      self.tableView.beginUpdates() 
     } 

func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange sectionInfo: NSFetchedResultsSectionInfo, atSectionIndex sectionIndex: Int, for type: NSFetchedResultsChangeType) { 
     print(sectionIndex) 
     print(sectionInfo.indexTitle) 
     switch type { 
     case .insert: 
      self.tableView.insertSections(IndexSet(integer: sectionIndex), with: .fade) 
     case .delete: 
      self.tableView.deleteSections(IndexSet(integer: sectionIndex), with: .fade) 
     default: 
      break 
     } 
    } 

    func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange anObject: Any, at indexPath: IndexPath?, for type: NSFetchedResultsChangeType, newIndexPath: IndexPath?) { 
     switch type { 
     case .update: 
      self.tableView.reloadRows(at: [indexPath!], with: .fade) 
      if indexPath == self.selectedIndexPath { 
       self.selectedIndexPath = indexPath 
      } 
      break 
     case .insert: 
      self.tableView.insertRows(at: [newIndexPath!], with: .fade) 
      self.selectedIndexPath = nil 
      break 
     case .delete: 
      self.tableView.deleteRows(at: [indexPath!], with: .fade) 
      self.selectedIndexPath = nil 
      break 
     case .move: 
      self.tableView.moveRow(at: indexPath!, to: newIndexPath!) 
      if indexPath == self.selectedIndexPath { 
       self.selectedIndexPath = newIndexPath 
      } 
      break 
     } 
    } 

func controllerDidChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) { 
     self.tableView.endUpdates() 
    } 
} 

答えて

0

とタイトル「アンattente」と1つのセクションあなたのcellForRowでミスを犯していますし、あなたのFetchedResultsデリゲート。

あなたがreloadRowsを使用しないでください.updateに、FetchedResultsControllerを使用している場合、この問題が発生し、代わりにあなたがそうのような細胞モデルを更新するメソッドを持つ必要があります:あなたのデリゲートで次に

func updateCell(atPath indexPath: IndexPath) { 
    if let cell = tableView.cellForRow(at: indexPath) as? MyCell { 
     updateCell(withCell: cell, atIndexPath: indexPath) 
    } 
} 

func updateCell(withCell cell: MyCell, atIndexPath indexPath: IndexPath) { 
    if let MyModel = fetchedResultsController?.object(at: indexPath) { 
     cell.model = myModel 
} 
} 

はあなたを.update updateCell(AtIndexPath)を呼び出して、セルのUIを更新します。

あなたはまた、あなたのcellForRowに悲しいことに、あなたの応答 ため

+0

感謝をこの細胞configureメソッドを使用する必要があり、それはバグでは解決しません:/ –

+0

とでも呼ばれるmoveRow時点で、私はちょうど現在のindexPathがあることがわかり(0,0)、newIndexPathが(0,1)の場合、ペアの最初の値はセクションのように見え、2番目の値は行のようです。 しかし、この時点でセクション0は削除されていないようです。 まず、cellをindexPath(1、x)に移動してから0を削除する必要があると感じます。 moveを使用する代わりにmoveRow –

+0

の前に呼び出されたtestSectionが呼び出され、indexPathを削除してnewIndexPathを挿入すると、 .update on the newIndexpAth – SeanLintern88

関連する問題