swift - Snapkit 和 TableView 中的多个自定义单元格

标签 swift uitableview snapkit

我使用 UItableView 作为用户个人资料页面的基础。我有几个自定义单元格。第一个自定义单元格是包裹在 ScrollView 中的图像。当我打开此 View 时出现此错误:

"<SnapKit.LayoutConstraint:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="86b6feb7e5b2b4e7b4bfb2b6c6c5e7f4e2c0f3eaeaf5e5f4e3e3e8d0efe3f1c5e9e8f2f4e9eaeae3f4a8f5f1efe0f2" rel="noreferrer noopener nofollow">[email protected]</a>#143 UIScrollView:SCROLL_VIEW.top == Lez.ProfileImagesCell:0x12a02e800.top>",
"<SnapKit.LayoutConstraint:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="25155d14461517441c141d1565664457416350494956465740404b734c4052664a4b51574a494940570b56524c4351" rel="noreferrer noopener nofollow">[email protected]</a>#144 UIScrollView:SCROLL_VIEW.height == 512.0>",
"<SnapKit.LayoutConstraint:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="605018510350520159510550202301120426150c0c13031205050e36090517230f0e14120f0c0c05124e1317090614" rel="noreferrer noopener nofollow">[email protected]</a>#145 UIScrollView:SCROLL_VIEW.bottom == Lez.ProfileImagesCell:0x12a02e800.bottom - 16.0>",
"<NSLayoutConstraint:0x1c0094690 'UIView-Encapsulated-Layout-Height' Lez.ProfileImagesCell:0x12a02e800'ProfileImagesCell'.height == 44   (active)>"

这是此单元格的自定义代码:

class ProfileImagesCell: UITableViewCell {
    var scrollView = UIScrollView()

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupScrollView()
        layoutIfNeeded()
    }

    private func setupScrollView() {
        addSubview(scrollView)
        let x = frame.width * 1.6
        scrollView.snp.makeConstraints { (make) in
            make.top.left.right.equalToSuperview()
            make.height.equalTo(x)
            make.bottom.equalToSuperview().inset(16)
        }
        scrollView.snp.setLabel("SCROLL_VIEW")
        scrollView.auk.settings.contentMode = .scaleAspectFill
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

我认为高度有问题,但我无法解决这个问题。任何输入都会被赞赏。

最佳答案

这个冲突背后的原因UIView-Encapsulated-Layout-Height是cell的初始高度,你可以尝试将scrollView底部约束的优先级设置为999,我的意思是这个

make.bottom.equalToSuperview().inset(16)

关于swift - Snapkit 和 TableView 中的多个自定义单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49466878/

相关文章:

ios - swift:swift 中的 SnapKit 不起作用

ios - 错误的工作日符号 (weekdaySymbols)

arrays - 转换字符串?

swift 3 : Tableview select row goes to different navigation views

objective-c - 是否可以刷新 UITableView 中的单个 UITableViewCell?

ios - 带有 AutoLayout 的 UICollectionViewCell 在 iOS 10 中不起作用

ios - 你如何使用 Swift 从 PDF 中提取图像?

swift - 动画链中的第一个 SKAction 无法正常工作

uitableview - 我可以在同一个 View Controller 中有一个 CollectionView 和一个 TableView