2016-08-01 83 views
0

好的,所以我的應用程序運行良好,過了一段時間,單元格不再工作。TableView顯示空白單元格

  1. 的的tableView被連接到數據源和代表
  2. 當運行該應用程序,控制檯正在打印陣列
  3. 內的所有值,其示出了3個單元,但內部

    var names = ["Bob", "Bill", "Billy"] 
    
    func numberOfSectionsInTableView(tableView: UITableView) -> Int { 
        return 1 
    } 
    
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
        return names.count 
    } 
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    
        let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! NamesCell 
    
        cell.name.text = self.names[indexPath.row] 
    
        return cell 
    } 
    
    沒有信息

    NamesCell(自定義單元)

    @IBOutlet weak var name: 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 
    } 
    
+0

可以請你提供你所得到的截圖嗎,還可以放一行cell.backgroundColor = UIColor.redColor() –

+0

什麼是你的代碼中的NamesCell?這是您創建的自定義類嗎? –

+0

檢查名稱標籤的高度,可能爲零。如果缺失,請在故事板中設置行高。 – MShah

回答

0

好吧,所以我清除了約束條件並將相同的約束條件重新添加到單元格標籤上,並且工作正常。很奇怪?

0

刪除約束並再次添加它們,這是一個約束問題。你的代碼是可以的。