尝试使用结构:
struct Sale {
var saleAmount : Double = 0.00
var soldBy : String = ""
var division : String = ""
var saleDate : Date?
}
类ViewController:uiViewController{
var arrayOfSaleData = [Sale]()
override func viewDidLoad(){
loadDataIntoArray()
}
func loadDataIntoArray(){
let mainSaleAmount = saleAmountData as? Double ?? 0
let sold = soldData as? String ?? ""
let div = divisionData as? String ?? ""
let mainSaleDate = saleDateData as! Date
//populate your struct with the received data
let allData = Sale(saleAmount: mainSaleAmount , soldBy: sold , division: div , saleDate: mainSaleDate )
self.arrayOfSaleData(allData)
DispatchQueue.main.async {
tabelView.reloadData()
}
}
}
extension ViewController : UITableViewDataSource, UITableViewDelegate{
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int)
-> Int {
return arrayOfSaleData.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = Bundle.main.loadNibNamed("YourTableViewCell", owner: self, options: nil)?.first as! YourTableViewCell
//Here you can assign your table view cell elements with data from your struct array
cell.saleAmountLabel.text = arrayOfSaleData[indexPath.row]. saleAmount
return cell
}