Is it possible to force value in property setter?
What I want is to override UINavigationBar tintColor setter and force default color to it. Bellow is my code开发者_运维知识库 (which of course fails). Is there a way to make it work?
@implementation UINavigationBar (UINavigationBarCategory)
- (void)setTintColor:(UIColor *)tint {
self.tintColor = [UIColor greenColor];
}
@end
(I'm using property
as a generic term here, in your example it's a stand-in for tintColor
)
I don't think you can use the self.property =
syntax for assignment inside a setProperty:
method. self.property
is just an alias for [self setProperty:<value>]
and it will recursively call itself.
You'll have to do something like this:
- (void)setProperty:(id)pProperty {
[property autorelease];
property = [pProperty retain];
}
I'm still not 100% sure what you're trying to do will work, but the preceding is a start.
If you want to force a default color of a NavigationBar, why don't you set the tint color in viewDidLoad/viewDidAppear of your view controller??
self.navigationController.navigationBar.tintColor = [UIColor (color you want)];
精彩评论