![](/img/trans.png)
[英]Swift Custom UITableViewCell Programmatically works and shows in cell but Storyboard IBOutlet is nil and does not show in cell
[英]Custom UITableViewCell created using Storyboard shows no label data - Swift
問題:我有一個簡單的 UITableViewController 並想在自定義單元格中顯示 label。 我創建了一個簡單的 UITableViewController,其中第 1 部分和第 4 行是硬編碼的。 在 storyboard 中,使用新的 label 自定義單元格,給它一個標識符並在 DemoTableViewCell 中映射一個出口。 以下是所有不同代碼片段的快照。 對我來說,在 function 中分配的 label 文本仍然沒有顯示。
class DemoTableViewCell: UITableViewCell {
@IBOutlet weak var demoLabel: UILabel!
}
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return 4
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell : DemoTableViewCell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath) as! DemoTableViewCell
cell.demoLabel.text = "Override Label"
// Configure the cell...
return cell
}
有人可以讓我知道我做錯了什么嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.