Simulate multiple inheritance in Objective-C

I have an abstract class for mine UIViewControllers(lets call it MyViewController) that overrides some basic methods, such as viewDidLoador viewDidDisappear. Some preparations are made in these methods, such as setting colors for the navigation bar or preparing the panel buttons or something like that.

Now I want this basic behavior for mine UITableViewControllers. So I created a new class that inherits UITableViewController(lets call it MyTableViewController) and copied 99% of the code from MyViewController.

UML diagram of the current situation

. , . , MyViewController MyTableViewController 99% - ( - ).

.

MyTableViewController MyViewController, UITableViewController?

+4
2

, , , .

UIViewcontroller. :

@implementation UIViewController (myCategory)
- (void)setupColors;
...
@end

MyViewcontroller MyTableViewcontroller UIViewController, .

, , , .

- viewDidLoad...
{
     [self setupColors];
}

, , [super...] ,

+4

, . (, viewDidLoad:), . , ( singleton) MyViewController, MyTableViewController, :

@interface MyViewController : UIViewController
@property (nonatomic, strong) MyControllerStyler *controllerStyler;
@end

@implementation MyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [controllerStyler viewDidLoad];
}
...etc...

, , :

@interface MyControllerStyler : NSObject

- (void)viewDidLoadInController: (UIViewController *)controller;
...etc...

, (, ), , ( ) .

+1

Source: https://habr.com/ru/post/1528041/


All Articles