[ad_1]
I am trying to reload my TableView but I am getting this exception "Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to delete row 3 from section 1 which only contains 0 rows before the update'".
Below is my code :-
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int 
 if statusTableView == tableView 
 return ModelAssessStatus.sharedInstance.arrType.count
 
 else 
 if !sections[section].expanded 
 return 0
 
 else 
 return sections[section].names.count
 
 //return sections[section].names.count
 /*if sections[section].expanded == true 
 return sections[section].names.count
 
 else 
 return 0
 */
 
. 
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell 
 var expandableCategoryCell = tableView.dequeueReusableCell(withIdentifier: "ExpandableCategoryCell") as? ExpandableCategoryCell
 if expandableCategoryCell == nil 
 var nib:Array = Bundle.main.loadNibNamed("ExpandableCategoryCell", owner: self, options: nil)!
 expandableCategoryCell = nib[0] as? ExpandableCategoryCell
 
 expandableCategoryCell?.selectionStyle = .none
 expandableCategoryCell?.labelName.text = sections[indexPath.section].names[indexPath.row]
 return expandableCategoryCell!
 //return UITableViewCell()
 . 
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat 
 if tableView == self.expandableTableView 
 return 60
 
 return 0
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat 
 if tableView == self.expandableTableView 
 return 0
 
 return 0
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? 
 if tableView == expandableTableView 
 let cell = self.expandableTableView.dequeueReusableHeaderFooterView(withIdentifier: "ExpandableHeaderView")
 let header = cell as! ExpandableHeaderView
 header.customInit(title: sections[section].categoryType, section: section, delegate: self, isSelected: sections[section].fullSelected)
 if sections[section].expanded 
 header.imgArrow?.image = UIImage(named : "down_Arow")//.transform = (header.imgArrow?.transform.rotated(by: CGFloat(Double.pi)))!
 
 else 
 header.imgArrow?.image = UIImage(named : "error")
 
 return cell
 
 else 
 return UIView.init(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
 
//Height For Raw at indexPath
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat 
 if statusTableView == tableView 
 return 50
 
 else 
 if (sections[indexPath.section].expanded) 
 return 60
 
 else 
 return 0
 
 
 
}
extension PeerCategoryStatusVC : expandableHeaderViewDelegate 
func toggleSections(header: ExpandableHeaderView, section: Int) 
 sections[section].expanded = !sections[section].expanded
 //expandableTableView.reloadData()
 expandableTableView.beginUpdates()
 for index in 0..<sections[section].names.count 
 expandableTableView.reloadRows(at: [IndexPath(row : index, section : section)], with: .automatic)
 
 expandableTableView.endUpdates()
 //self.view.layoutIfNeeded()
 
. 
Here Begin Update and End Update TableView. 
I am trying to reload tableView but don't know why I am getting exception. 
If I will keep same number of rows then constraints issue is coming.
Is there anything which I have to add ?
[ad_2]
لینک منبع
