自定义单元格没有出现在表视图,Xcode的
问题描述:
我已经做了自定义单元格,并使用它的.xib显示在表视图。 但该小区is'nt显示表view.While其他自定义孔细。自定义单元格没有出现在表视图,Xcode的
单元控制器:
import UIKit
//Protocol to add action on button click
protocol ChatLinkButtonDelegate: class {
func chatLinkClick(cell: ChatBankController)
}
class ChatBankController: UITableViewCell {
@IBOutlet weak var btnseemore: CustomUIButton!
@IBOutlet weak var year: CustomUILabel!
@IBOutlet weak var anwser: CustomUILabel!
@IBOutlet weak var month: CustomUILabel!
@IBOutlet weak var interest: CustomUILabel!
var delegate: ChatLinkButtonDelegate?
override func prepareForReuse() {
super.prepareForReuse()
self.delegate = nil
}
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
}
@IBAction func btnChatLinkClick(_ sender: Any) {
self.delegate?.chatLinkClick(cell: self)
}
}
表视图控制器加载和显示数据: 注册:
cell = UINib(nibName: "ChatBank", bundle: nil)
self.tbChat.register(cell, forCellReuseIdentifier: "ChatBankCell")
加载电池实现代码如下:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell:ChatBankController = self.tbChat.dequeueReusableCell(withIdentifier: "ChatBankCell") as! ChatBankController
cell.anwser.text="fine"
return cell
let cell = UITableViewCell()
return cell
}
答
注册笔尖文件在您查看controller.swift文件视图执行加载方法并设置tableview数据rce和代表像
override func viewDidLoad() {
super.viewDidLoad()
yourTableView.register(UINib.init(nibName:"ProfileTableViewCell" , bundle: nil), forCellReuseIdentifier: "ProfileTableViewCell")
yourTableView.datasource = self
yourTableView.delegate = self
}
答
首先请检查您是否连接故事板中表视图的代表和数据源。
那就试试这个代码:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = self.tbChat.dequeueReusableCell(withIdentifier: "ChatBankCell") as! ChatBankController
cell.anwser.text="fine"
return cell
}
+0
它的数据源,delegeted连接,因为其他自定义单元格是工作的罚款它只有1个标签或1 button.But这是越来越这种定制电池故障问题有一些标签和一个按钮。 –
你已经设置的tableview委托或数据源 – Jaydip
您可以检查是否正确,如果出列单元格?添加debugPrint(小区)的'让细胞下面:ChatBankController = self.tbChat.dequeueReusableCell'线和发布的内容打印 –
感谢答复,小区信息:> –