gpt4 book ai didi

ios - 我如何支持 iOS7 上的自调整单元格?

转载 作者:IT王子 更新时间:2023-10-29 05:20:55 26 4
gpt4 key购买 nike

随着 iOS8 的发布,我设计了带有单元格的表格 View ,利用了自动调整单元格的优势。但我也需要我的表格在 iOS7 中工作。我怎么做?有没有一种方法可以检查运行时是否支持自调整单元格大小,或者我可以在我的 Controller 中实现一些在 iOS7 中不会调用的表委托(delegate)方法吗?

如果我在 iOS7 中尝试使用自调整单元格的表格,我会在控制台上收到如下错误:

Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0x7fc912d1d5a0 V:|-(>=11)-[UILabel:0x7fc912d13900] (Names: '|':UITableViewCellContentView:0x7fc912d13400 )>",
"<NSLayoutConstraint:0x7fc912d1d6b0 V:[UILabel:0x7fc912d13900]-(11)-| (Names: '|':UITableViewCellContentView:0x7fc912d13400 )>",
"<NSAutoresizingMaskLayoutConstraint:0x7fc912d24d80 h=--& v=--& V:[UITableViewCellContentView:0x7fc912d13400(0.5)]>"
)

最佳答案

这是我迄今为止找到的解决方案,但它需要检查特定版本号而不是功能。如果您的版本为 iOS 8 或更高版本,您只需设置 UITableViewAutomaticDimension:

override func viewDidLoad() {

if NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1 {
self.tableView.estimatedRowHeight = 80
self.tableView.rowHeight = UITableViewAutomaticDimension
}
}

对于 iOS 7,您需要计算每个单元格的高度。但是,如果您使用的是 iOS 8,则可以返回 UITableViewAutomaticDimension 作为高度:

override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1 {
return UITableViewAutomaticDimension
}
return 50 // Or whatever calculated value you need for cell height
}

关于ios - 我如何支持 iOS7 上的自调整单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26282051/

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