简体   繁体   English

应用程序崩溃如果在滚动 UITableView 时 popViewController

[英]App crash If popViewController while scrolling UITableView

Hello I have UIViewController inside UINavigationController which has a UITableView in it.您好,我在UINavigationController中有UIViewController ,其中有一个UITableView I'm reseting my data model when user tap back button (which triggers popViewController function of UINavigationController ).当用户点击后退按钮(触发UINavigationController popViewController功能)时,我正在重置我的数据模型。 If I popViewController , while scrolling UITableView , App crashes on cellForRowAt function.如果我popViewController ,在滚动UITableView ,App 在cellForRowAt函数上崩溃。 What can cause this problem?什么会导致这个问题?

cellForRowAt function: cellForRowAt函数:

class MyViewController: UIViewController, TableView... {

var myChecksModel: MyChecksModel!
.
.
.

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: MyChecksListTableViewCell = tableView.dequeueReusableCell(withIdentifier: cellId) as? MyChecksListTableViewCell ??
    MyChecksListTableViewCell(style: .default, reuseIdentifier: cellId)
let check = self.myChecksModel.chequeList[indexPath.row]
cell.myChecksData = check
return cell
}

Back Button返回键

@objc func backButtonTapped(_ sender: UIButton) {
DispatchQueue.main.async {
    self.myChecksModel.resetModel()
    self.navigationController?.popViewController(animated: true)
}
}

Reset Model Function重置模型功能

class MyChecksModel: Codable {
var chequeList: [MyClass] = []
func resetModel() {
self.chequeList = []
}

Your app is crashing because of您的应用程序崩溃是因为

index out of bound索引越界

You should call你应该打电话

self.myChecksModel.resetModel()

In

override func viewDidDisappear(_ animated: Bool) {
      super.viewDidDisappear(animated)

      self.myChecksModel.resetModel()
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 滚动UITableView时发生随机崩溃 - Random crash while scrolling UITableView 滚动UITableview时发生崩溃 - Crash happening while Scrolling the UITableview AutoLayout视图使popViewController上的应用程序崩溃 - AutoLayout views make app crash on popViewController iOS:滚动UITableView时,应用程序崩溃/内存已满 - iOS : app crash / memory is filled in when scrolling a UITableView 从uitableview cellForRowAtIndexPath委托中删除行时,应用程序崩溃 - app crash while deleting row from within uitableview cellForRowAtIndexPath delegate 滚动uitableview时,应用程序在main.m @autoreleasepool中崩溃 - App gets crashed in main.m @autoreleasepool while scrolling uitableview UITableView滚动崩溃使应用程序崩溃 - UITableView scrolling crashes app 当我在滚动UITableview期间显示文档目录中的图像时,内存不断增加然后应用程序崩溃 - Memory continuously increase then app crash when i display image from document directory during scrolling UITableview 如何解决 uiTableview 滚动应用程序崩溃,它在 swift 中引发数组索引超出范围异常? - How do I solve the uiTableview scrolling app crash which throws array index out of bound exception in swift? 快速滚动时带有AlamofireImage的Swift UItableview崩溃 - Swift UItableview with AlamofireImage crash when scrolling fast
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM