ios - 自定义单元格内容不显示 Swift

标签 ios xcode uitableview swift3 custom-cell

我想创建一个自定义表格 View 。我有一个 UITableViewController:

class MainListView: UITableViewController{
var invoceList: [InvoceObject] = []
@IBOutlet var tbMain: UITableView!

  override func viewDidLoad() {
    super.viewDidLoad()
    self.tableView.register(CustomCell.self, forCellReuseIdentifier: "cell")
    tbMain.delegate = self
    self.tbMain.dataSource = self
    }

  override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()        
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return self.invoceList.count
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! CustomCell        
    cell.lblBuyerName?.text = self.invoceList[indexPath.row].BUYER_NAME
    cell.lblDate?.text = self.invoceList[indexPath.row].CREATED_AT
    cell.lblPriceGross?.text = self.invoceList[indexPath.row].PRICE + " " + self.invoceList[indexPath.row].CURRENCY

    cell.backgroundColor = UIColor(white: 1, alpha: 0.5)      
    return cell
    }
}

还有我的 UITableViewCell 类:
class CustomCell: UITableViewCell {
@IBOutlet weak var lblBuyerName: UILabel!
@IBOutlet weak var lblDate: UILabel!
@IBOutlet weak var lblPriceGross: UILabel!   

override func awakeFromNib() {
    super.awakeFromNib()
    // Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)
    // Configure the view for the selected state
}
}

构建后,我得到一个空单元格。我有许多行,例如 invoceList.count,但没有标签,它看起来像空表。我做错了什么?

最佳答案

由于您使用的是 UITableViewController有一个隐含的 tableView具有连接的数据源和委托(delegate)的属性。您应该使用它来避免混淆。

并删除 self.tableView.register... 行如果您使用的是原型(prototype)单元。

关于ios - 自定义单元格内容不显示 Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41700056/

相关文章:

适用于 native 应用程序的 iPhone 模拟器/解释器(为 ARM 编译)

iphone - 相机功能在 iPhone 上不起作用

ios - 获取嵌套 JSON 中的每个对象

objective-c - 核心数据内存使用和内存警告

xcode - 连接文件所有者以查看问题

ios - 如何使用图像的缓存目录

ios4 - 使用 SDWebImage 将图像加载到 UITableView 单元格时出现问题

iphone - UITableViewCell 显示 UIImageView 或 UIProgressView

iphone - 在 iOS 中更改句子部分文本的颜色

ios - UITableView 和 UICollectionView 更新新单元格问题