由于未捕获的异常而终止应用程序,原因:'attempt to delete row 3 from section 1 which only contains 0 rows before the update'
Terminating app due to uncaught exception, reason: 'attempt to delete row 3 from section 1 which only contains 0 rows before the update'
我正在尝试重新加载我的 TableView,但出现此异常 "Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to delete row 3 from section 1 which only contains 0 rows before the update'"。
下面是我的代码:-
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()
}
}.
此处开始更新并结束更新 TableView。
我正在尝试重新加载 tableView 但不知道为什么会出现异常。
如果我将保留相同的行数,那么就会出现约束问题。
有什么要补充的吗?
我只是修复了同样的异常。主要是因为你调用 reloadRows(at: with:)
的 indexPath(s) 的 row
大于总行数。
我正在尝试重新加载我的 TableView,但出现此异常 "Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to delete row 3 from section 1 which only contains 0 rows before the update'"。
下面是我的代码:-
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()
}
}.
此处开始更新并结束更新 TableView。 我正在尝试重新加载 tableView 但不知道为什么会出现异常。
如果我将保留相同的行数,那么就会出现约束问题。
有什么要补充的吗?
我只是修复了同样的异常。主要是因为你调用 reloadRows(at: with:)
的 indexPath(s) 的 row
大于总行数。