【发布时间】:2018-01-17 09:38:18
【问题描述】:
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat
{
let chatMessageStarModel = arrMentionChat[indexPath.row]
if let key = chatMessageStarModel.chatMessageMarkerID?.stringValue() {
if let valueHeight = cellHeight[key] , valueHeight > 0.0{
return valueHeight
}
}
else {
return UITableViewAutomaticDimension
}
return UITableViewAutomaticDimension
}
我希望该函数 estimatedHeightForRowAt 仅适用于 Ios 11 或更高版本,而不适用于 Ios 10 或任何其他更低版本。如果我使用
@available(iOS 11.0, *)
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat
{
let chatMessageStarModel = arrMentionChat[indexPath.row]
if let key = chatMessageStarModel.chatMessageMarkerID?.stringValue() {
if let valueHeight = cellHeight[key] , valueHeight > 0.0{
return valueHeight
}
}
else {
return UITableViewAutomaticDimension
}
return UITableViewAutomaticDimension
}
我尝试的另一种方法是:-
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat
{
if #available(iOS 11.0,*) {
let chatMessageStarModel = arrMentionChat[indexPath.row]
if let key = chatMessageStarModel.chatMessageMarkerID?.stringValue() {
if let valueHeight = cellHeight[key] , valueHeight > 0.0{
return valueHeight
}
}
else {
return UITableViewAutomaticDimension
}
return UITableViewAutomaticDimension
}
}
我知道我需要返回一些东西但是如果我返回 0.0 或 UITableViewAutomaticDimension 而不是在 Ios 10 中,这个函数将运行并且我的情况会受到干扰。
那么如何只在 ios 11 上运行这个功能,而它在 ios 10 上无论如何都不能运行来实现这个功能呢?
【问题讨论】:
-
你项目的目标是什么iOS版本?
-
ios 9 是目标
-
And.. 你是直接在 UIViewController 子类上定义estimatedHeightForRowAt 方法还是使用符合UITableViewDelegate 的自定义类?
-
最后一个问题:“在 Ios 10 中,此功能将运行,我的情况将受到干扰”是什么意思——表格视图是否显示高度错误的单元格?
-
是的,如果此功能在 iOS 10 中运行,我的手机会受到干扰
标签: ios iphone swift uitableview ios11