我想只改变一个类的用户列表,称为网络。我不明白如何在userList更改后进行TableView更新。我将在下面的代码中向您展示一个示例和详细问题。如何在某些数据更改后刷新TableView?
// Network.swift
class Network {
var userList: [User] = []
// Next functions may change userList array
// For example, the data came from the server, and update the userList with new data
}
// App delegate
class AppDelegate: UIResponder, UIApplicationDelegate {
var network: Network = Network()
..
}
// File TableViewController.swift
class TableViewController: UITableViewController {
…
var userList: [User] = [] // Here I want to have a full copy of the array from Network class
override func viewDidLoad() {
super.viewDidLoad()
let appDelegate = UIApplication.shared.delegate as! AppDelegate
self.userList = appDelegate.network.userList // Just copy an array
// And I want that after each update appDelegate.network.userList I updated the table, how to do it better?
self.tableView.reloadData()
}
}
你的架构是非常散乱和坏(为什么保持这一个的appdelegate VAR)这是怎么清单得到更新?谁是网络的来电者以检查更新? – JDM