我正在使用以下代码扩展我的单元格:
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)
}
}
}
这是问题的图片:
我以前在扩展单元格时从未遇到过分隔线出现在那里而不是在扩展单元格下方的问题。但这次无论出于什么原因,它出现了,我不知道如何将它放在展开的单元格下。
以下是我在 MainStoryBoard 中设置单元格的方法:
现在,我尝试更改原始高度,这会导致该线移动。但我希望原始高度为 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/