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

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

问题描述

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

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 是从<$加载的c $ c>故事板,带 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论坛 上阅读时( 此处此处 )其他人有这样的问题,并找到一些解决方法,例如:

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测试版中看到的那样,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 $ c>子类,现在可以可靠地显示分隔符:

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

Objective-C

- (void)layoutSubviews {
    [super layoutSubviews];

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

Swift

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天全站免登陆