I have made a custom cell and using its .xib to show in table view. But the this cell is'nt showing in table view.While other custom cells are fine.
Cell Controller:
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)
}
}
Table View controller to load and show data: Registration:
cell = UINib(nibName: "ChatBank", bundle: nil)
self.tbChat.register(cell, forCellReuseIdentifier: "ChatBankCell")
Loading cell to tableview:
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
}
Register nib file in your view controller.swift file view did load method and set tableview datasource and delegate like
override func viewDidLoad() {
super.viewDidLoad()
yourTableView.register(UINib.init(nibName:"ProfileTableViewCell" , bundle: nil), forCellReuseIdentifier: "ProfileTableViewCell")
yourTableView.datasource = self
yourTableView.delegate = self
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments