我目前遇到UITableView问题。
我从json文件中获取一些数据并将它们放在表视图中,但是对于表视图有一种奇怪的反应。 当我打开应用程序时,它在单元格中没有任何东西,当我再往下走,然后回到顶部时,它看起来应该出现在单元格内部。 如果我走下去,它会消除细胞内的文本。
代码
in ViewDidLoad
let nib = UINib(nibName: "homeTableViewCell", bundle: nil)
// Register the nib for reusing within the tableview with your reuseidentifier
self.activitiesTable.registerNib(nib, forCellReuseIdentifier: "homeCell")
self.activitiesTable.delegate = self
self.activitiesTable.dataSource = self
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("homeCell", forIndexPath: indexPath) as! homeTableViewCell
cell.lblContentHomeCell.text = "test"
return cell
}
以下是模拟器的截图。
即使我在每个单元中正常写“test”仍然有同样的问题。 细胞是定制细胞。 有没有人有同样的问题,并找到了解决方案?非常感谢您的帮助。
答案 0 :(得分:2)
我的第一个应用程序遇到了类似的问题。您似乎必须定义每个单元格的高度。你可以获得单元格的高度并返回它,或使用标准值,如下所示: (在您的表视图中,代理人添加了这个)
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 100.0;
}