So I have to admit, that I had this code working perfectly up until a day or so ago when I added a new view, so I'm rather frustrated at the moment.
The setup: I have a storyboarded app that contains a tabbar. In the AppDelegate, I have the following for attaching the CoreData
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UINavigationController *navigationController = [[tabBarController viewControllers] objectAtIndex:0];
GamesViewController *controller = [[navigationController viewControllers] objectAtIndex:0];
controller.managedObjectContext = self.managedObjectContext;
return YES;
}
Also in the AppDelegate, I had this method that would set the standard tab background to an image of my choosing:
- (void)customizeInterface {
UIImage* tabBarBackground = [UIImage imageNamed:@"tab_background"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
}
So this all worked fine until I added another login view that precedes my tabs. I had to change what the CoreData was initially being set too (from my tabs to my login/initializing view). Below is the new setup of how the storyboard looks.
Now when the app loads up... the background image appears initially as before, but only on the first tab. Once I click off if it, it switches to the default gradient color again. If I go back to the first / initial tab, the background does not-reapply itself, it stays as the colored gradient.
Here is the amended applicationDidFinishLaunching code to go along with it:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//instantiate local context
NSManagedObjectContext *context = [self managedObjectContext];
if (!context) {
// Handle the error.
NSLog(@"Error: Context is null");
}
LoginViewController *rootViewController = [LoginViewController alloc];
rootViewController.managedObjectContext = context;
return YES;
}
So then what I tried to do, is go into the viewDidLoad in the first VC that my tabbar loads up (GameViewController) and tried adding this to fix the problem:
- (void)viewDidLoad {
[super viewDidLoad];
[self.tabBarController.tabBar setBackgroundImage:[UIImage imageNamed:@"dock_background"]];
}
That didn't work, so I also tried using the same original code that I had in my AppDelegate and that also didn't work:
- (void)viewDidLoad {
[super viewDidLoad];
UIImage* tabBarBackground = [UIImage imageNamed:@"tab_background"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
}
So... I'm sort of stuck. I've got to be doing (or not doing) something so obvious... Anyone out there have any tips / pointers?
Thanks a ton - Drew