Ios 财产';窗口';在类型为';CustomTabBar';
我想做的是在我的iOS应用程序中自定义Ios 财产';窗口';在类型为';CustomTabBar';,ios,objective-c,uitabbarcontroller,Ios,Objective C,Uitabbarcontroller,我想做的是在我的iOS应用程序中自定义uitabaritems的文本和图像。我想我可以通过使用CustomTabBar类对UITabBarController进行子类化来实现这一点 当我尝试使用下面的代码执行此操作时,会出现一个错误,说明:在“CustomTabBar”类型的对象上找不到属性“window”。如何正确地将UITabBarController子类化,以便自定义文本和图像 CustomTabBar.h: #import <UIKit/UIKit.h> #import &l
uitabaritem
s的文本和图像。我想我可以通过使用CustomTabBar
类对UITabBarController
进行子类化来实现这一点
当我尝试使用下面的代码执行此操作时,会出现一个错误,说明:在“CustomTabBar”类型的对象上找不到属性“window”
。如何正确地将UITabBarController
子类化,以便自定义文本和图像
CustomTabBar.h:
#import <UIKit/UIKit.h>
#import <Parse/Parse.h>
#import <Parse/PFCloud.h>
@interface CustomTabBar : UITabBarController
@end
#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
您发布的代码位于选项卡栏控制器子类中,因此选项卡栏控制器只是“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";
}