[英]how to stop refreshing the tableview when scroll down?
I have a table view that has many checkmark cells. 我有一个具有许多选中标记单元格的表视图。
When I scroll down or up, the tableView and puts a check mark randomly without clicking on the cell. 当我向下或向上滚动时,tableView会随机放置一个复选标记,而无需单击单元格。
I want to stop that refreshing. 我想停止这种刷新。
This is my code: 这是我的代码:
import UIKit
class AmenitiesView: UIViewController, UITableViewDelegate,UITableViewDataSource {
@IBOutlet weak var tableView: UITableView!
var Count:Int = 0
var arrType:[String] = ["Balcony","Basement","Garage","Central Air","Dining room","Driver Room","Fiber Optic","Fireplace","Furniture","Internal Stair","Kitchen","Laundry","Lift","Maid Room","Parking","Swimming Pool"]
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return arrType.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Type") as! PropertySizeChoosen!
cell?.pType.text = arrType[indexPath.row]
return cell!
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if tableView.cellForRow(at: indexPath)?.accessoryType == UITableViewCellAccessoryType.checkmark {
tableView.cellForRow(at: indexPath)?.accessoryType = UITableViewCellAccessoryType.none
Count -= 1
}else{
tableView.cellForRow(at: indexPath)?.accessoryType = UITableViewCellAccessoryType.checkmark
Count += 1
}
}
}
Don't try to stop refreshing, its basically a UITableView's feature which is for performance. 不要试图停止刷新,它基本上是UITableView的功能,可以提高性能。 just save the state in your model/object/array/collection and repopulate your cell in
CellForItemAtIndexPath
只需将状态保存在模型/对象/数组/集合中,然后在
CellForItemAtIndexPath
重新填充单元格
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.