Created
January 15, 2013 06:13
-
-
Save JimRoepcke/4536602 to your computer and use it in GitHub Desktop.
Putting a category on model classes to specialize UI/layout code for each model type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In MyViewController.m | |
@interface BaseModelClass (MyViewControllerLayout) | |
// If your model classes don't have a common superclass, put | |
// this category on NSObject instead | |
- (void)layoutForMyViewController:(MyViewController *)controller; | |
@end | |
@implementation ModelA (MyViewControllerLayout) | |
- (void)layoutForMyViewController:(MyViewController *)controller | |
{ | |
// layout ModelA object for MyViewController | |
} | |
@end | |
@implementation ModelB (MyViewControllerLayout) | |
- (void)layoutForMyViewController:(MyViewController *)controller | |
{ | |
// layout ModelB object for MyViewController | |
} | |
@end | |
@implementation ModelC (MyViewControllerLayout) | |
- (void)layoutForMyViewController:(MyViewController *)controller | |
{ | |
// layout ModelC object for MyViewController | |
} | |
@end | |
@implementation MyViewController | |
- (void)someLayoutMethod | |
{ | |
for (BaseModelClass *modelObject in self.modelObjects) | |
{ | |
[modelObject layoutForMyViewController:self]; | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment