ios - 滚动或重新加载表格 View 后查看位置变化

标签 ios swift uitableview swift4

第一次加载表格 View 时看起来不错,但问题是滚动表格 View 或重新加载表格 View 然后 lineView 位置发生变化。

func drowLine(_ cell: UITableViewCell)->UIView{
    let lineView = UIView(frame: CGRect(x: 20, y: cell.contentView.frame.size.height - 1.0, width: cell.contentView.frame.size.width - 40 , height: 1))
    lineView.backgroundColor = UIColor(red: 56/255, green: 66/255, blue: 72/255, alpha: 0.149)
    return lineView
}


 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let  cell = tableView.dequeueReusableCell(withIdentifier: titleDisclosureIndicatorID, for: indexPath) as! TitleDisclosureIndicatorCell
       //......
        cell.contentView.addSubview(drowLine(cell))
    return cell
}


class TitleDisclosureIndicatorCell: BaseTableViewCell {

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: .value1, reuseIdentifier: reuseIdentifier)
    }
   //.....

}

初始加载 TableView :

enter image description here

滚动并重新加载 tableview 行位置后更改一些行:

enter image description here

最佳答案

单元格正在被重复使用,所以我猜您一直在多次添加该行。 您应该以不同的方式处理此问题并使用 RegistrationFormCell 的子类。将该行添加到您的 Storyboard 文件中,您将不会再遇到这个问题。

关于ios - 滚动或重新加载表格 View 后查看位置变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46951710/

相关文章:

ios - 一旦所有项目出现在 View Controller 中,就关闭 UIAlertView

ios - 将字典存储到 Firebase 中?

ios - UICollectionView 中仅某些单元格之间的自定义间距

ios - UITableView 中的 UITapGestureRecognizer - 第一个单元格被点击手势忽略

ios - Objective-c 如何从 UITableView 子类中进行 Segue

ios - 可展开的 UItableview 内容高度在展开或折叠期间不同

ios - 对于iPad/iPhone apps,如何拥有一个数组点?

ios - 如何按日期排序获取请求而不需要时间 - Swift 3

ios - 获取info.plist的fileSize,防止盗版

ios - iOS8 中的 UIWindow 无法正确旋转