UITableViewCell 分隔符在 iOS15 中消失

UITableViewCell Separator disappearing in iOS15

提问人:towa x 提问时间:10/18/2021 更新时间:6/15/2022 访问量:671

问:

我尝试像这样添加分隔线。

图像1

但是当没有数据时,分隔线会消失。

图片2

谁能帮我解决这个问题?谢谢。

Swift Objective-C UITableView iPad iOS15

评论


答:

0赞 Maxim 10/18/2021 #1

Towa X! 这可以通过向 Separator 添加选项来解决。在 MainStoryBoard 中,转到 Attributes Inspector/Separator。将其更改为“默认”-分隔符在任何条件下显示:空或已填充。

-1赞 Ranjit Singh 10/19/2021 #2

在函数中添加以下内容:viewDidLoad

yourTableViewReference.fillerRowHeight = UITableViewCellSeparatorStyleSingleLine
0赞 Elliot Czigány 6/15/2022 #3

公认的答案甚至没有编译! 根据文档,您必须将 设置为 automaticDimensions。fillerRowHeigt

因此,编写方法是,将这行代码添加到您或您设置 tableView 的部分:viewDidLoad

tableView.fillerRowHeight = UITableViewAutomaticDimension

此变量仅在 iOS 15 之后可用,因此要支持旧版本,请使用:

if #available(iOS 15.0, *) {
   tableView.fillerRowHeight = UITableViewAutomaticDimension
}