简体   繁体   中英

Multiple views with on single nib

I have a collection view that shows a list of recipes. There are multiple types of recipes that are presented in slightly different ways (different text color, etc.) but they're visually quite similar.

The way I think of doing it:

Have a single recipe UICollectionViewCell inside a nib. There's a generic RecipeCollectionViewCell that holds all IBOutlets. Each recipe type would then be a subclass of the generic RecipeCollectionViewCell and implement its own configureWithRecipe() method. That way, the parent class stays clean and the configuration is pushed down to the subclasses.

My question is now: Is there some way to configure the same nib for multiple UICollectionViewCell subclasses?

registerNib:forIdentifier: won't work since I can't specify which class to use. registerClass: forCellWithReuseIdentifier: won't work since I can't provide that it should be loaded from a nib. :/

yes you can add as subview in all your cell classes. So the overall case would be like You have a view named ABCView which will have its nib and all iboutlets will be connected so that all the configuration will take place in this class. Now in all your cell classes you can load this ABCView and add it as subview.To communicate between ABCView and Cell class you can have delegate methods .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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