Reputation: 859
What I want to do is customize the text and images of the UITabBarItem
s in my iOS app. I figured I would do this by subclassing UITabBarController
with the CustomTabBar
class.
When I try to do it with the below code, I get an error stating: Property 'window' not found on object of type 'CustomTabBar'
. How can I correctly subclass UITabBarController
so that I can customize the text and images?
CustomTabBar.h:
#import <UIKit/UIKit.h>
#import <Parse/Parse.h>
#import <Parse/PFCloud.h>
@interface CustomTabBar : UITabBarController
@end
CustomTabBar.m:
#import "CustomTabBar.h"
@interface CustomTabBar ()
@end
@implementation CustomTabBar
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
// Assign tab bar item with titles
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UITabBar *tabBar = tabBarController.tabBar;
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1];
tabBarItem1.title = @"Search";
tabBarItem2.title = @"MatchCenter";
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
Upvotes: 0
Views: 809
Reputation: 104082
The code you posted is in your tab bar controller subclass, so the tab bar controller is just "self".
- (void)viewDidLoad {
[super viewDidLoad];
UITabBar *tabBar = self.tabBar;
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1];
tabBarItem1.title = @"Search";
tabBarItem2.title = @"MatchCenter";
}
Upvotes: 2