[英]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.