tôi có một cái UITableView
,它基本上是一个 To-Do-List。有没有一种方法可以“自动重新排序”列表,以便“选中”单元格
自动进入列表底部,从而使“未选中”项目保持在顶部?
我希望你明白为什么我的问题是.. 有什么不清楚的就问。我找不到与该主题相关的任何内容,因此非常感谢您的帮助! :)
đây là của tôiUITableView
:
import UIKit
class WhishlistTableViewController: UITableViewController {
public var wishList = [Wish]()
override func viewDidLoad() {
super.viewDidLoad()
// disable prefill tableview with cells
let v = UIView()
v.backgroundColor = .clear
tableView.tableFooterView = v
// disable didSelectAt
self.tableView.allowsSelection = false
self.tableView.register(WhishCell.self, forCellReuseIdentifier: WhishCell.reuseID)
self.wishList.append(Wish(withWishName: "Test"))
// add top inset for tavleview
self.tableView.contentInset = UIEdgeInsets(top: 10, left: 0, bottom: 0, right: 0)
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return wishList.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: WhishCell.reuseID, for: indexPath) as! WhishCell
let currentWish = self.wishList[indexPath.row]
cell.label.text = currentWish.wishName
cell.backgroundColor = .clear
return cell
}
}
class Wish: NSObject {
public var wishName : String?
init(withWishName name: String) {
super.init()
wishName = name
}
}
每次编辑数组中的任何项目时都需要执行此操作
wishList.partition(by: { $0.checked }) // it's mutating and ignore the return
我假设您在Wish
模型中checked
bool 属性
Tôi là một lập trình viên xuất sắc, rất giỏi!