Closed ghost closed 8 years ago
What about a table view cell superclass? I created a class called DesignTableViewCell, and put all of the design work that you're talking about (image views, labels, etc) in there. Then instead of:
ExampleTableViewCell: UITableViewCell {} OtherTableViewCell: UITableViewCell {}
have them inherit the design class:
ExampleTableViewCell: DesignTableViewCell {} OtherTableViewCell: DesignTableViewCell {}
It doesn't completely eliminate code duplication, but it lessens it.
Hmm, okay. I tried that refactor and it didn't work, so there's something I've gotta figure out. I'll do a workaround for now & probably update the app after the deadline.
@manglano You can use the same custom table view cell class for multiple view controllers.
When you add IBOutlets to your custom table view cell class, you drag from the storyboard to the class. You can add additional outlets to different view controllers by dragging in the opposite direction -- from the circle that appears to the left of the IBOutlet in the custom cell class to the label (or image view, button, etc.) in storyboard.
(You can't see where my mouse is in this screenshot, but I'm dragging from the IBOutlet in code towards the label in storyboard.)
Great! I will keep that in mind for the next iteration, other apps, etc.
A cell created in storyboard as a prototype cell for one table view can be programmatically instantiated as a prototype cell for a different table view, but its UIImageViews and UILabels (etc.) cannot be accessed from the different table view. The workaround is to create another prototype cell and TableViewCell subclass, but that's a lot of code duplication--is there some way to reuse the original class without duplicating?