【发布时间】:2018-10-23 10:42:03
【问题描述】:
我在网上搜索了我的问题,但对我的情况没有任何帮助。有点特别。
我的应用程序有一个清单功能,一切正常,但有这个问题。在UITableViewCell 上添加checkmark 并在此之后删除其他单元格之一。所有checkmarks 将被删除。
我的想法是,当某些内容被删除时,数组和连接会出现问题。我的意思是数组中属性的“顺序”。我问过我的同事 (IT),但没有人能帮助我。
class ViewControllerChecklist: UIViewController, UITableViewDelegate, UITableViewDataSource{
@IBOutlet weak var myTableView: UITableView!
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return (checklist.count)
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "cell")
cell.textLabel?.textColor = UIColor(red: 4 / 255.0, green: 59 / 255.0, blue: 101 / 255.0, alpha: 1.0)
cell.textLabel?.font = UIFont.boldSystemFont(ofSize: 18.0)
cell.textLabel?.text = checklist[indexPath.row]
return cell
}
// checkmarks when tapped
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.cellForRow(at: indexPath)?.accessoryType = .checkmark
tableView.deselectRow(at: indexPath, animated: true)
}
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == UITableViewCellEditingStyle.delete {
checklist.remove(at: indexPath.row)
myTableView.reloadData()
}
}
override func viewDidAppear(_ animated: Bool) {
myTableView.reloadData()
}
override func viewDidLoad() {
super.viewDidLoad()
UITableViewCell.appearance().tintColor = UIColor(red: 237 / 255.0, green: 108 / 255.0, blue: 4 / 255.0, alpha: 1.0)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
【问题讨论】:
标签: arrays swift uitableview