mbogh / NibDesignable

Elegant way of enabling IBDesignable on your nib-based views
MIT License
342 stars 74 forks source link

Update demo to show working example of UICollectionViewCell, etc #40

Closed sgtsquiggs closed 7 years ago

sgtsquiggs commented 8 years ago

I am implementing UICollectionViewCell the same way I would a regular UIView with NibDesignable but I can't get it to work. Always getting errors similar to this class is not key value coding-compliant for the key randomLabel.

farzadshbfn commented 8 years ago

This sounds more like a broken outlet connection. You're using NibDesignableCollectionViewCell right?

sgtsquiggs commented 8 years ago

My xib has a UICollectionViewCell inside. File owner is set to my custom ArtworkCollectionViewCell, which is a subclass of NibDesignableCollectionViewCell.

sgtsquiggs commented 8 years ago

I am not getting the original error anymore, but also I am not able to properly calculate the size of the cell (for use in a waterfall layout). Sizing always returns 0,0 with cell.contentView.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize)

I noticed you end up with a UICollectionViewCell within a UICollectionViewCell, would this be causing the issue?

farzadshbfn commented 8 years ago

You "can" use UIView in the nib file (and i suggest you to), because it's gonna be added to contentView of UICollectionViewCell anyway, If you use UICollectionViewCell in nib file, there's just gonna be more subviews (and cause performance issues). But it has nothing to do with the error you've mentioned earlier. Did you check all your outlet connections? and one more thing, your app crashes with this error? or you're just seeing this error in console?

If it's printed in console, You've probably set some attributes as @IBInspectable and removed it later... they're still there in User Defined Runtime Attributes

farzadshbfn commented 8 years ago

I guess so, I remember having this problem but I'm not sure using UIView in nib file fixed it, or something else.

sgtsquiggs commented 8 years ago

That somewhat fixed it. I've got some other bugs but using a simple UIView instead of a cell fixed sizing. This could be made clearer with a proper demo :)

farzadshbfn commented 8 years ago

I'm glad your problems solved :)

This bugged me for a while too (I even experienced recursive crash on IB 😃) but it's written in ReadMe file: Create a nib, place a UIView and change the File's Owner to CustomView

I think it should indicate more boldly that you should use UIView for all NibDesignables

sgtsquiggs commented 8 years ago

Yeah. In the past with other nib designables I used the cell class directly with no file owner. Funky but it worked, which is how I was mixed up here.