【发布时间】:2015-01-09 04:06:29
【问题描述】:
设置附件后,我无法让自定义 UITableViewCell 正确调整大小。为什么附件会在初始显示上放大单元格大小?当我使用附件集滚动时,尺寸会自行纠正 - 但是,初始视图的尺寸不正确。
我已经多次观看 WWDC14(tableview 中的新功能)视频,并且阅读了许多 stackoverflow 问题并尝试了许多解决方案。我想我已经解决了大部分问题 - 单元格确实为动态文本调整大小 - 但我对这种奇怪的初始行为感到困惑。我正在运行 XCode 6.1.1 部署到 iOS 8.1。
我正在使用故事板。我有一个 UITableViewController 和自定义 UITableViewCell。我在情节提要中定义了约束,没有约束警告,并且在运行时在控制台中没有看到约束消息。
在我的 UITableViewController viewDidLoad()
tableView.estimatedRowHeight = 44
tableView.rowHeight = UITableViewAutomaticDimension
有覆盖
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("TableViewCell", forIndexPath: indexPath) as TableViewCell
cell.configure(titles[indexPath.row])
return cell
}
这是我的整个自定义 UITableViewCell
class TableViewCell: UITableViewCell {
@IBOutlet weak var titleLabel: UILabel!
func configure(title: NSString) {
titleLabel.text = title
titleLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleBody)
}
override func layoutSubviews() {
super.layoutSubviews()
titleLabel.preferredMaxLayoutWidth = frame.width
}
}
这是在单元格上设置无附件时的样子
这是我在单元格上设置附件披露指示器时的样子
再次,当我使用附件集滚动时,尺寸会自行纠正。我尝试在情节提要中向单元格添加垂直约束,也尝试通过以编程方式添加所有约束但没有成功。感谢您的任何想法。
【问题讨论】:
标签: ios uitableview swift