正如標題所示,我試圖顯示鏈接到控制器的標籤中的一些文本,但無法顯示除空白單元格外的任何內容。每個標籤都正確連接到控制器,但單元格仍然是空的。代碼有問題嗎?TableView顯示空單元格
import UIKit
class TableViewCell: UITableViewCell{
@IBOutlet weak var label1: UILabel!
@IBOutlet weak var label2: UILabel!
@IBOutlet weak var Date: UILabel!
}
class Controller: UIViewController, UITableViewDataSource,UITableViewDelegate {
let textCellIdentifier = "ShowCell"
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.delegate = self
self.tableView.dataSource? = self
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "ShowCell")
LeagueData.single.addListener {
self.tableView.reloadData()
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// return team.count
return 7
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "ShowCell") as! TableViewCell!
cell?.label1?.text = "sample text" //LeagueData.single.schedule[0].team1.name
cell?.label2.text = LeagueData.single.schedule[0].team2.name
cell?.Date.text = LeagueData.single.schedule[0].date
print(LeagueData.single.schedule[0].date)
return cell!
}
}
分享你的故事板/ XIB文件? –
你在tableview中使用自定義的單元格嗎? –