So I have a class A in which I have the following:
@implementation UIToolbar (A)
- (void)drawRect:(CGRect)rect {
UIColor *color = [UIColor colorWithWhite:0.0 alpha:1.0];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColor(context, CGColorGetComponents( [color CGColor]));
CGContextFillRect(context, rect);
self.tintColor = [UIColor colorWithWhite:0.0 alpha:1.0];
}
@end
and I have a class B, which I have the following:
@implementation UIToolbar (B)
- (void)drawRect:(CGRect)rect {
UIColor *color = [UIColor colorWithWhite:10.0 alpha:1.0];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColor(context, CGColorGetComponents( [color CGColor]));
CGContextFillRect(context, rect);
self.tintColor = [UIColor colorWithWhite:0.0 alpha:1.0];
}
@end
Question is why is it only the top level category called each time? I basically want to have a different UIToolbar color/configuration for each different UIViewController, how do I do so?
A and B are not classes, they’re categories. Any given class can only have one implementation of a given method at a time. If you try to override a method in more than one category, which implementation you get is undefined. Indeed, it’s not recommended to override methods in categories at all — if you need to override, you should create a subclass.