我有一个UITableView,它的顶部边缘连接到UIButton的底部。UITableView的边缘连接到屏幕的边缘。
UITableView有一个高度约束,最初设置为0,然后在按下UIButton时,将高度约束常数动画为所需的大小,从而有效地将UITableView扩展到UIButton下面。再次点击UIButton使常量恢复到0,并再次折叠和隐藏UITableView。
我遇到的问题是,在UITableView的第一次加载/扩展时,当单元格出现时,它们似乎不是正确的宽度--右手端(包括其内容)似乎略有扩展。如果我折叠UITableView,然后再重新展开它,错误就不会发生,所以它似乎只发生在单元的第一个负载上。
我已经尝试过这两种默认Value1类型的单元格,以及来自Nibs的自定义单元格,这两个单元格都会出现问题。
我也尝试过在cell.layoutIfNeeded()和cell.layoutSubviews()之前调用cellForRowAtIndexPath()中的return cell,但两者都没有效果。
这个问题只发生在iPhone 6和更高版本的上,大概是因为屏幕从这个设备上稍微变宽了。在iPhone 5S及更高版本上,细胞首次加载良好。似乎这些电池最初以iPhone 5S和较低的宽度加载,然后在较大的设备上向外扩展。
问题似乎与更改UITableView的高度约束常量有关,但我不知道为什么。
提前感谢您的帮助。
编辑
添加了cellForRowAtIndexPath()代码:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("Cell") as UITableViewCell?
if (cell == nil) {
cell = UITableViewCell(style: UITableViewCellStyle.Value1, reuseIdentifier: "Cell")
}
cell!.textLabel?.font = UIFont(name: "HelveticaNeue", size: 14)
cell!.textLabel?.textColor = UIColor.lightGrayColor()
cell!.textLabel?.text = self.someArray[indexPath.row]
return cell!
}发布于 2016-02-03 11:10:44
尝尝这个
var cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell?
if (cell == nil) {
cell = UITableViewCell(style: UITableViewCellStyle.Value1, reuseIdentifier: ("Cell", forIndexPath: indexPath))
}https://stackoverflow.com/questions/35175182
复制相似问题