gpt4 book ai didi

ios - 添加附件后,自定义 UITableViewCell 的大小不正确

转载 作者:行者123 更新时间:2023-11-28 09:15:31 25 4
gpt4 key购买 nike

设置附件后,我无法让自定义 UITableViewCell 正确调整大小。为什么配件会在初始显示时放大单元格尺寸?当我使用附件集滚动时,尺寸会自行更正 - 但是,初始 View 尺寸不正确。

我已经多次观看 WWDC14(tableview 中的新功能)视频,并且阅读了许多 stackoverflow 问题并尝试了许多解决方案。我想我已经解决了大部分问题 - 单元格会针对动态文本调整大小 - 但我对这种奇怪的初始行为感到困惑。我正在运行部署到 iOS 8.1 的 XCode 6.1.1。

我正在使用 Storyboard。我有一个 UITableViewController 和自定义 UITableViewCell。我在 Storyboard 中定义了约束,但没有约束警告,而且我在运行时的控制台中也没有看到任何约束消息。

在我的 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
}

这是在单元格上设置 Accessory None 时的样子

enter image description here

这是我在单元格上设置附件泄露指示器时的样子

enter image description here

同样,当我滚动附件设置时,尺寸会自行更正。我已经尝试在 Storyboard中向单元格添加垂直约束,也尝试以编程方式添加所有约束但没有成功。感谢您的任何想法。

最佳答案

我在 Storyboard设计的自调整单元格中也遇到过这个问题。尝试将 self.layoutIfNeeded() 添加到单元格类中的 didMoveToSuperview 覆盖中。我不知道这是不是一个错误,或者我们只是错过了一些我们应该做的事情。

关于ios - 添加附件后,自定义 UITableViewCell 的大小不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27853658/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com