iOS9 的 UITableview 分隔符未隐藏
UITableview separator not hiding for iOS9
我已经通过编码实现了 UITableView
。我也设置了UITableViewCellSeparatorStyleNone
。它隐藏 iOS8 及以下但不隐藏 iOS9 Beta。
根据我的调查,不是 iOS 9 有问题,而是 Xcode 7.0 beta 4。
如果我使用 Xcode 7.0 beta 4 构建应用程序,即使在 Interface Builder 中设置为 None,单元格分隔符也会显示。如果我使用 Xcode 6.4 或 7.0 beta 3 构建相同的代码,则不会显示分隔符。
作为解决方法,您可以在 ViewController 中明确调用它:
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
(我猜ibtool
可能有问题)
我有同样的问题,在 iOS 8 上工作正常,但在 iOS9 中显示分隔符。我已经将分隔符样式设置为 none。以下为我解决了它
if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
cell.preservesSuperviewLayoutMargins = NO;
}
cell.separatorInset = UIEdgeInsetsMake(0.f, 0.f, 0.f, cell.bounds.size.width);
if([cell respondsToSelector:@selector(setLayoutMargins:)]) {
cell.layoutMargins = UIEdgeInsetsZero;
}
这基本上是使用插图压缩分隔符。
将分隔符样式设置为 .None
对我不起作用,所以我使用边缘插入作为 hack 解决方法
self.tableView.separatorInset.left = UIScreen.mainScreen().bounds.width
这个问题很烦人。这是我的解决方案:
override func didMoveToSuperview() {
if self.superview != nil {
self.tableView.separatorStyle = .None
}
}
当视图添加到其父视图时再次设置 separatorStyle。
apple developer forum 中对我有用的解决方案:
您可以通过在每个 reloadData 方法之前设置 UITableViewCellSeparatorNone 来删除分隔符 (ios 9.1)。我不知道为什么,但是 UITableView 每次调用 reloadData 方法后都会重置 separatorStyle 和 separatorColor。
请在 layoutSubviews 方法中将分隔符样式设置为 None。
当使用基于约束的布局时,基本实现会应用基于约束的布局,并在此方法中将 separatorStyle 设置为 UITableViewCellSeparatorStyleNone 将为您隐藏分隔符。
我也遇到了同样的问题。我的解决方法是设置
tableView.separatorColor = UIColor.clearColor()
.
myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
对于Swift
myTableView.separatorStyle = UITableViewCellSeparatorStyle.None
in cellForRowAtIndexPath 方法将在 iOS 9 及更高版本中隐藏白线。
下面的代码对我有用,
override func layoutSubviews() {
super.layoutSubviews()
tableView.separatorStyle = .none
}
我已经通过编码实现了 UITableView
。我也设置了UITableViewCellSeparatorStyleNone
。它隐藏 iOS8 及以下但不隐藏 iOS9 Beta。
根据我的调查,不是 iOS 9 有问题,而是 Xcode 7.0 beta 4。
如果我使用 Xcode 7.0 beta 4 构建应用程序,即使在 Interface Builder 中设置为 None,单元格分隔符也会显示。如果我使用 Xcode 6.4 或 7.0 beta 3 构建相同的代码,则不会显示分隔符。
作为解决方法,您可以在 ViewController 中明确调用它:
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
(我猜ibtool
可能有问题)
我有同样的问题,在 iOS 8 上工作正常,但在 iOS9 中显示分隔符。我已经将分隔符样式设置为 none。以下为我解决了它
if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
cell.preservesSuperviewLayoutMargins = NO;
}
cell.separatorInset = UIEdgeInsetsMake(0.f, 0.f, 0.f, cell.bounds.size.width);
if([cell respondsToSelector:@selector(setLayoutMargins:)]) {
cell.layoutMargins = UIEdgeInsetsZero;
}
这基本上是使用插图压缩分隔符。
将分隔符样式设置为 .None
对我不起作用,所以我使用边缘插入作为 hack 解决方法
self.tableView.separatorInset.left = UIScreen.mainScreen().bounds.width
这个问题很烦人。这是我的解决方案:
override func didMoveToSuperview() {
if self.superview != nil {
self.tableView.separatorStyle = .None
}
}
当视图添加到其父视图时再次设置 separatorStyle。
apple developer forum 中对我有用的解决方案:
您可以通过在每个 reloadData 方法之前设置 UITableViewCellSeparatorNone 来删除分隔符 (ios 9.1)。我不知道为什么,但是 UITableView 每次调用 reloadData 方法后都会重置 separatorStyle 和 separatorColor。
请在 layoutSubviews 方法中将分隔符样式设置为 None。
当使用基于约束的布局时,基本实现会应用基于约束的布局,并在此方法中将 separatorStyle 设置为 UITableViewCellSeparatorStyleNone 将为您隐藏分隔符。
我也遇到了同样的问题。我的解决方法是设置
tableView.separatorColor = UIColor.clearColor()
.
myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
对于Swift
myTableView.separatorStyle = UITableViewCellSeparatorStyle.None
in cellForRowAtIndexPath 方法将在 iOS 9 及更高版本中隐藏白线。
下面的代码对我有用,
override func layoutSubviews() {
super.layoutSubviews()
tableView.separatorStyle = .none
}