도움이 필요하십니까? iOS 9에서만 버그가 나타납니다. 아래에서 볼 수 있듯이 , 그것은 시작에 UITableView 업데이트시 오류 발생
아이폰 OS (11)에 잘되어 가고, 나는 새에 대한 상태 "누보"와 4 개 세포를 가지고있다. "새로운"셀을 클릭하면 상태가 "En attente"("대기 중")로 바뀝니다.iOS 9에서는 모든 것이 마지막 셀까지 괜찮습니다. 마지막 "새"셀을 탭하면 "대기 중"으로 이동하지 않고 "새"섹션이 그대로 남아 있습니다. 이 후, 테이블 뷰는 더 이상 업데이트를 얻지 못하고, 다른 viewController로 변경하고 다시 테이블 뷰를 포함하는 것으로 돌아갈 때 정상으로 돌아갑니다.
NSFetchedResultsController를 사용하고 있습니다. 데이터는 섹션의 양호한 수, 좋은 수, 섹션 별 요소 수, 좋은 제목입니다.
4 오브젝트 당신은 당신의 cellForRow와 실수를 한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()
}
}
덕분에이 셀의 구성 방법을 사용한다 :/ –
을하지만 moveRow가 호출 될 때, 난 그냥 현재 indexPath가 참조 (0,0)이고 newIndexPath가 (0,1)이면 쌍의 첫 번째 값은 섹션으로 보이고 두 번째 값은 행으로 보입니다. 그러나 지금은 섹션 0이 삭제되지 않은 것 같습니다. 먼저 indexPath (1, x)에 셀을 이동 한 다음 섹션 0을 삭제해야합니다. move를 사용하는 대신 moveRow –
전에 테스트하고 deleteSection을 호출하고 indexPath를 삭제하고 newIndexPath를 삽입 한 다음 호출합니다. .update on the newIndexpAth – SeanLintern88