无法在表格视图中显示文本标签

我正在建立具有自定义单元格的表格视图。单元格应及时包含各种标签,但目前只有一个标签(用作测试)。

当我运行该应用程序时,一切看起来都很好,但是cell.textLabel.text没有出现在应用程序中。每个单元格为空白。

对于显示的数据,我在一个单独的文件中建立了一个模型,在这里可见:

import Foundation

class CountryDataModel {
    let countryName: String
    let casesData: String
    let deathsData: String
    let recoveriesData: String
    
    init(country: String, cases: String, deaths: String, recoveries: String) {
        
        countryName = country
        casesData = cases
        deathsData = deaths
        recoveriesData = recoveries
        
    }
}

这是表视图的视图控制器:

import UIKit

class PaysTableViewController: UITableViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Uncomment the following line to preserve selection between presentations
        
        listOfCountryAndRelatedData()
        
    }
    
    //MARK: - Relevant data
    var countryList = [CountryDataModel]()

    // MARK: - Table view data source

    override func numberOfSections(in tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 0
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return countryList.count
    }

    //
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)

        // Configure the cell...
        let indexPath = countryList[indexPath.row]
        
        cell.textLabel?.text = indexPath.countryName

        return cell
    }
    
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        print("success")
    }

 
    func listOfCountryAndRelatedData() {
        
        let country1 = CountryDataModel(country: "Algeria", cases: "0", deaths: "0", recoveries: "0")
        countryList.append(country1)
        
        let country2 = CountryDataModel(country: "Bahamas", cases: "0", deaths: "0", recoveries: "0")
        countryList.append(country2)
        
        let country3 = CountryDataModel(country: "Seychelles", cases: "0", deaths: "0", recoveries: "0")
        countryList.append(country3)
        
        
        
    }

}
评论