Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storyboard - Multiple UITableViewControllers with the same custom cell

I occasionally find myself copy/pasting custom cells between UITableViews in my storyboard which is slowly becoming a maintenance nightmare (i.e., a simple change must now be made to each custom cell across several UITableViews).

Is it possible to create one custom cell in a storyboard or xib file and then reference it from multiple UITableViews? I'm thinking there's got to be a way to specify a NIB name for a static/prototype cell similar to how you can specify a NIB name for a UIViewController when editing a normal xib.

BTW... I know how to do this via code. What I'm looking for is a way to do this from within the storyboard editor itself.

like image 211
KnightHawk Avatar asked Nov 13 '22 13:11

KnightHawk


1 Answers

I know of a way, but it does require a little code in a custom class. Make a subclass of UITableViewCell that loads itself from a nib. Then just set the class of your cells to this subclass. For a good method of having a view replace itself with a different version loaded from a nib see this blog post.

like image 75
Mr. Berna Avatar answered Nov 16 '22 02:11

Mr. Berna