I am making an app, and I want to the able to change the tint color of the UITabBarController. I created a custom class for UITabBarController and assigned it to the UITabBar in IB. It works fine. This class has an IBAction that changes it's color called alterColor:
That's all fine and well when the app first launches. But after that, I can not seem to run that action from another class. I have a settings class, where I try to change the color. I get the correct instance by doing the following in the settings class.
.H
@property (nonatomic, strong) TabBarController *tabController;
.M
@implementation LogbookThirdViewController
@synthesize CarbsTextField;
@synthesize tabController;
...
-(IBAction)colorRedPicked:(id)sender {
NSString *writableDBPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"colorChoice.txt"];
NSString *carbRatio = @"red";
[carbRatio writeToFile:writableDBPath atomically:YES encoding:NSUTF16StringEncoding error:nil];
NSString *readFile;
readFile = [NSString stringWithContentsOfFile:writableDBPath encoding:NSUTF16StringEncoding error:nil];
NSLog(@"Color = %@", readFile);
readFile = nil;
[tabController alterColor:tabController]; //This line should run the method.
}
However, nothing happens.
Assuming that this viewController is contained within your tabbarController, you don't need that property.
There is an existing property on UIViewController:
@property(nonatomic, readonly, retain) UITabBarController *tabBarController
(you don't need to add that in code, it is in the class you inherit from when you make your viewController sublcass)
Refer to the tabBarController thus:
self.tabBarController
You may need to typecast it to your custom controller to encourage the compiler to allow you to send your colorchanging method to it. But either way you will be getting the message to the correct object.