【问题标题】:Snapkit and multiple custom cells in TableViewSnapkit 和 TableView 中的多个自定义单元格
【发布时间】:2018-03-24 16:06:00
【问题描述】:

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

"<SnapKit.LayoutConstraint:0x1c42a2940@CardFullscreenViewController.swift#143 UIScrollView:SCROLL_VIEW.top == Lez.ProfileImagesCell:0x12a02e800.top>",
"<SnapKit.LayoutConstraint:0x1c02a9180@CardFullscreenViewController.swift#144 UIScrollView:SCROLL_VIEW.height == 512.0>",
"<SnapKit.LayoutConstraint:0x1c02a91e0@CardFullscreenViewController.swift#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")
    }
}

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

【问题讨论】:

    标签: swift uitableview snapkit


    【解决方案1】:

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

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

    【讨论】:

    • 就是这样!谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多