ios - UITableView 行分隔线在扩展单元格时行为不正确

标签 ios swift uitableview

我正在使用以下代码扩展我的单元格:

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    let originalHeight: CGFloat = 48.0
    let expandedHeight: CGFloat = 135
    let indexPath = indexPath
    if self.expandButtonTappedIndexPath != nil {
        if indexPath == self.expandButtonTappedIndexPath! {

            return expandedHeight
        } else {
            return originalHeight
        }
    } else {
        return originalHeight
    }
}

还有

@IBAction func expandButtonTapped(sender: AnyObject) {

    switch self.expandButtonTappedIndexPath {
    case nil:
        self.expandButtonTappedIndexPath = indexPath
    default:
        if self.expandButtonTappedIndexPath! == indexPath {
            self.expandButtonTappedIndexPath = nil
        } else {
            self.expandButtonTappedIndexPath = indexPath
            //self.tableView.scrollToRowAtIndexPath(indexPath!, atScrollPosition: .Top, animated: true)
        }
    }
}

这是问题的图片:

enter image description here

我以前在扩展单元格时从未遇到过分隔线出现在那里而不是在扩展单元格下方的问题。但这次无论出于什么原因,它出现了,我不知道如何将它放在展开的单元格下。

以下是我在 MainStoryBoard 中设置单元格的方法:

enter image description here

现在,我尝试更改原始高度,这会导致该线移动。但我希望原始高度为 48.0,并且希望分隔线移动到展开单元格的底部,而不是笨拙地位于中间。

关于如何解决这个问题有什么建议吗?预先非常感谢您的帮助:)

最佳答案

我道歉。我应该做更多的研究。答案可以在这里找到: UITableView displays separator at wrong position in iOS8 for some cells

我只需在单元格中的 layoutSubviews() 函数中调用父类(super class)即可。我像这样道歉:

override func layoutSubviews() {
    super.layoutSubviews()
}

关于ios - UITableView 行分隔线在扩展单元格时行为不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37052398/

相关文章:

ios - 如果今天是本月的最后一天,如何添加日期。?

ios - Swift 多项选择输入答案

iphone - 无法从 for-in 循环中更新 NSMutableDictionary 值?

ios - 内部测试时 ITSAppUsesNonExemptEncryption 导出合规性?

ios - Swift - 隐藏和显示对象

ios - 如何使用 Interface Builder 在 iPhone 5 上扩展 UITableView 以填满全屏?

ios - UITableview 剖面 View 上的 UIbutton 没有动画效果

swift - 设置页脚 View UITableView 的背景颜色不起作用

ios - 通过 UIViewController 传递触摸

ios - 如何跟踪保存在 iPhone 或 iPad 中的提醒?