【发布时间】:2018-10-05 20:28:03
【问题描述】:
我从另一个 ViewController 添加或删除 我在 tableView 中显示这个 array.count 我如何快速自动更新array.count的单元格? 没有 Timer 和 Pull 刷新
或者当loadedCart.count 发生变化时如何进行刷新? 谢谢
class TestTABLEVC: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var tableViewT: UITableView!
var CellT = TestTableViewCell()
var def = UserDefaults.standard
var loadedCart = [[String:Any]]()
override func viewDidLoad() {
super.viewDidLoad()
tableViewT.estimatedRowHeight = 100
tableViewT.dataSource = self
tableViewT.delegate = self
loadedCart = UserDefaults.standard.array(forKey: "cartt") as? [[String: Any]] ?? []
//Here need add auto update
}
行的单元格
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TestTableViewCell
let item = loadedCart[indexPath.row]
cell.nameLbl?.text = item["name"] as? String
cell.priceLbl.text = item["price"] as? String
cell.qntLbl.text = item["qty"] as? String
let im = item["image"] as? NSData
cell.PhoroUmage.image = UIImage(data: im! as Data)
return cell
}
Btn,点击时 - 删除 arr 并重新加载单元格
@IBAction func Btn(_ sender: UIButton) {
def.removeObject(forKey: "cartt")
print("remove is OK")
//Here need add auto update when btn pressed
}
【问题讨论】:
-
你的意思是 tableViewT.reloadData() 吗?
-
reloadData 无法自动更新我的单元格
标签: arrays swift uitableview io reload