简体   繁体   English

查看UICollectionViewCell的调试?

[英]View debugging of UICollectionViewCell?

Is there a way to debug UI of custom UICollectionViewCell in XCode? 有没有一种方法可以在XCode中调试自定义UICollectionViewCell UI? All I can see in the view debugging of the UICollectionView is the cell being displayed as one solid UIView without any subviews, like this: UICollectionView的视图调试中,我所看到的就是将单元格显示为一个没有任何子视图的实体UIView,如下所示:

查看调试

I would like to see all the subviews so I could easily debug UILabel frames and so on. 我希望看到所有子视图,以便可以轻松调试UILabel框架等。 Thank you. 谢谢。

I had the same issue.. finally figured out this occurs when you add subviews directly to UICollectionViewCell instead of adding subviews to it's contentView . 我有同样的问题..最终发现,将子视图直接添加到UICollectionViewCell而不是将子视图添加到它的contentView时会发生这种情况。

Example: 例:

This codes shows properly in the view debugger: 此代码在视图调试器中正确显示:

class Cell: UICollectionViewCell {
    var fillView: UIView? {
        didSet {
            guard oldValue != fillView else {return}

            oldValue?.removeFromSuperview()

            if let fillView = fillView {
                contentView.addSubview(fillView)
            }
        }
    }
}

This does not show properly in the view debugger: 这在视图调试器中无法正确显示:

class Cell: UICollectionViewCell {
    var fillView: UIView? {
        didSet {
            guard oldValue != fillView else {return}

            oldValue?.removeFromSuperview()

            if let fillView = fillView {
                // Note: not adding to `contentView`
                addSubview(fillView)
            }
        }
    }
}

I strongly recommend the Tool of Reveal ,it's a very powerful debugger tool for UI 我强烈推荐Reveal工具,它是用于UI的非常强大的调试器工具

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM