2016-08-01 111 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

删除约束并再次添加它们,这是一个约束问题。你的代码是可以的。

相关问题