2017-08-08 94 views
0

我已經做了自定義單元格,並使用它的.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 
    } 
+0

你已經設置的tableview委託或數據源 – Jaydip

+0

您可以檢查是否正確,如果出列單元格?添加debugPrint(小區)的'讓細胞下面:ChatBankController = self.tbChat.dequeueReusableCell'線和發佈的內容打印 –

+0

感謝答覆,小區信息: > –

回答

0

註冊筆尖文件在您查看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 

    } 
+0

感謝您的回覆,但它沒有奏效。 –

+0

你可以註冊Nib文件嗎? – Jaydip

+0

按照您提及的方法做同樣的事情。 –

0

首先請檢查您是否連接故事板中表視圖的代表和數據源。

那就試試這個代碼:

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這是越來越這種定製電池故障問題有一些標籤和一個按鈕。 –

相關問題