UITableViewCell 分隔符在 iOS7 中消失 [英] UITableViewCell Separator disappearing in iOS7

查看:31
本文介绍了UITableViewCell 分隔符在 iOS7 中消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 UITableView 有一些奇怪的问题,只有在 iOS 7 中.

I have some strange issue with UITableView only in iOS 7.

UITableViewCellSeparator 消失在第一行上方和最后一行下方.有时在选择行或一些滚动操作后会出现.

UITableViewCellSeparator disappears above the first row and below the last row. Sometimes after selecting the rows or some scrolling actions it appears.

在我的例子中 tableView 是从 Storyboard 加载的,带有 UITableViewStylePlain 样式.问题肯定不在 UITableViewCellSeparatorStyle 中,它与默认的 UITableViewCellSeparatorStyleSingleLine 没有改变.

In my case tableView is loaded from the Storyboard with UITableViewStylePlain style. The problem is surely not in UITableViewCellSeparatorStyle, which is not changed from default UITableViewCellSeparatorStyleSingleLine.

正如我在 Apple Dev Forums 所读到的那样(此处此处) 其他人有这样的问题并找到了一些解决方法,例如:

As I read at Apple Dev Forums (here and here) other people have such problem and some workarounds are found, for example:

Workaround: disable the default selection and recreate the behaviour in a method
trigged by a tapGestureRecognizer.

但我仍在寻找这种分隔符奇怪行为的原因.

But I am still searching for the reason of such separator strange behaviour.

有什么想法吗?

更新: 正如我在 XCode 5.1 DP 和 iOS 7.1 beta 中看到的那样,Apple 试图解决这个问题.现在分隔符有时会根据需要显示在最后一行下方,经过一些刷新,但不是在创建 tableview 之后.

Update: As I saw in XCode 5.1 DP and iOS 7.1 beta, Apple tried to fix this problem. Now separator is shown as needed sometimes below the last row, after some refreshing, but not after tableview creation.

推荐答案

我转储了受影响单元格的子视图层次结构,发现 _UITableViewCellSeparatorView 被设置为隐藏.难怪没有显示!

I dumped the subview hierarchy of affected cells and found that the _UITableViewCellSeparatorView was set to hidden. No wonder it's not shown!

我在我的 UITableViewCell 子类中覆盖了 layoutSubviews,现在分隔符可以可靠地显示:

I overrode layoutSubviews in my UITableViewCell subclass and now the separators are displayed reliably:

目标 C:

- (void)layoutSubviews {
    [super layoutSubviews];

    for (UIView *subview in self.contentView.superview.subviews) {
        if ([NSStringFromClass(subview.class) hasSuffix:@"SeparatorView"]) {
            subview.hidden = NO;
        }
    }
}

斯威夫特:

override func layoutSubviews() {
    super.layoutSubviews()

    guard let superview = contentView.superview else {
        return
    }
    for subview in superview.subviews {
        if String(subview.dynamicType).hasSuffix("SeparatorView") {
            subview.hidden = false
        }
    }
}

此处提出的其他解决方案对我来说效果不佳或显得笨拙(添加自定义 1 px 页脚视图).

The other solutions proposed here didn't work consistently for me or seem clunky (adding custom 1 px footer views).

这篇关于UITableViewCell 分隔符在 iOS7 中消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆