gpt4 book ai didi

ios - 在 'window' 类型的对象上找不到属性 'CustomTabBar'

转载 作者:行者123 更新时间:2023-11-28 21:59:04 26 4
gpt4 key购买 nike

我想做的是在我的 iOS 应用程序中自定义 UITabBarItem 的文本和图像。我想我会通过使用 CustomTabBar 类子类化 UITabBarController 来做到这一点。

当我尝试使用以下代码执行此操作时,我收到一条错误消息:在“CustomTabBar”类型的对象上找不到属性“window”。如何正确地子类化 UITabBarController 以便我可以自定义文本和图像?

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

最佳答案

您发布的代码在您的标签栏 Controller 子类中,因此标签栏 Controller 只是“ 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";
}

关于ios - 在 'window' 类型的对象上找不到属性 'CustomTabBar',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25556590/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com