Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
501 views
in Technique[技术] by (71.8m points)

iphone - Defining UICollectionViewCell with nib

If I understand correctly, the content of a UICollectionViewCell should go inside its contentView property and the background into backgroundView.

Yet, when I drag a UICollectionViewCell to Interface Builder there is no mention of contentView or backgroundView. If I add subviews, those will have the whole cell as its parent, not contentView or backgroundView.

What is the right way of defining a UICollectionViewCell with IB, then?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

"If I add subviews, those will have the whole cell as its parent, not contentView"

This is not true. If you drag in a UICollectionViewCell, and add UI elements to it, you are adding them to the content view. The fact that it doesn't show up in the objects list doesn't mean it's not there (the same is true for NSBox - it has a content view that doesn't show up in IB either). If in collectionView:didSelectItemAtIndexPath:, you log cellForItemAtIndexPath, and look at its subviews, you find only one, and it's the same one you get by logging cell.contentView. If you log its subviews, then you will see your UI elements.

Now, as far as background view, I don't think that's something you can access from IB. You can have a xib file with a UIView, and then assign that to the cell's backgroundView property.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...