Meet Doshi
Meet Doshi

Reputation: 4259

How to use one UIView for Custom TableViewCell and CollectionView Cell.?

I want to create same CustomCell for UICollectionView and UITableView. But I don't want to create different CustomCells for this both.

So How can I use same UIView for this cells.?

I want to create following screens into my application.

enter image description here enter image description here

Is there any solution for this.?

Any help would be appreciated.

Upvotes: 1

Views: 207

Answers (2)

user1105951
user1105951

Reputation: 2287

When dequeueReusableCell of collectionView or tableview.
1. Check if cell.contentView has subview of CustomView.
2. If not, create object of CustomView class and add as subview to cell.contentView
3. Fill CustomView with data.

Upvotes: 1

The1993
The1993

Reputation: 604

Create a .xib file for your CustomCell,

then just initialise it in your respective classes like:

UICollectionView.dequeueReusableCell()
UITableView.dequeueReusableCell()

Upvotes: 1

Related Questions