如何以 NIB 文件或编程方式更改 uitabBarItem 的标题

发布于 2024-12-22 10:49:05 字数 362 浏览 0 评论 0原文

这是在 viewDidLoad 和 viewWillAppear 中编写的代码行,但 uitabbar 项目标题仍然没有改变。

[[self.userTabBarController.viewControllers objectAtIndex:1] setTitle:@"您的标题"];

其中 userTabBarController 是

IBOutlet  UITabBarController *userTabBarController;

我的选项卡栏有 3 个选项卡,这些选项卡与 3 个不同的 viewController 连接,并且加载正常。

为什么没有设置标题,代码看起来没问题。

Here is the line of code which is written in viewDidLoad and viewWillAppear but still uitabbar item title is not being changed.

[[self.userTabBarController.viewControllers objectAtIndex:1] setTitle:@"Your title"];

Where userTabBarController is

IBOutlet  UITabBarController *userTabBarController;

My tabbar has 3 tabs and these are conecting with 3 different viewController and it is loading fine.

Why title is not being set, code is seems to look ok.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

美煞众生 2024-12-29 10:49:05

试试这个:

MyViewController *viewController = [self.userTabBarController.viewControllers objectAtIndex:1] 

[viewController setTitle:@"Your title"];

因为这对你不起作用,我建议你转到 tabbarcontroller 中视图控制器的实现文件,然后简单地执行:

self.title = @"my title";

在 vi​​ewDidLoad 方法中。

Try this:

MyViewController *viewController = [self.userTabBarController.viewControllers objectAtIndex:1] 

[viewController setTitle:@"Your title"];

Since that did not work for you I would suggest going to the implementation file of the view controller in your tabbarcontroller and simply doing:

self.title = @"my title";

in the viewDidLoad method.

第几種人 2024-12-29 10:49:05

试试这个:

UITabBar *tabBar = self.userTabBarController.tabBar;
UITabBarItem *tabBarItem = [[tabBar items] objectAtIndex:0];
[tabBarItem setTitle:@"New Title"];

Try this:

UITabBar *tabBar = self.userTabBarController.tabBar;
UITabBarItem *tabBarItem = [[tabBar items] objectAtIndex:0];
[tabBarItem setTitle:@"New Title"];
心如荒岛 2024-12-29 10:49:05

在 NIB 中,viewController 的 .m 文件中。像这样更改 initWithNibName 方法。将会起作用

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) 
    {
        [self setTabBarItem:[[UITabBarItem alloc] initWithTitle:@"Aktuelles" image:[UIImage imageNamed:@"News.png"] tag:0]];
        self.title = @"Aktuelles";
    }
    return self;
}

in NIB, .m file of your viewController..change your initWithNibName method like this.will work

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) 
    {
        [self setTabBarItem:[[UITabBarItem alloc] initWithTitle:@"Aktuelles" image:[UIImage imageNamed:@"News.png"] tag:0]];
        self.title = @"Aktuelles";
    }
    return self;
}
獨角戲 2024-12-29 10:49:05

在其 awakeFromNib 方法中设置视图控制器的 title 属性:

- (void) awakeFromNib
{
   self.title = "My Title";
}

Set the title property of the view controller in its awakeFromNib method:

- (void) awakeFromNib
{
   self.title = "My Title";
}
你在我安 2024-12-29 10:49:05

您可以在 IB 上进行探索,或者如果您不想在 appdelegate 文件中设置它,您可以使用以下命令:

[[self.parentViewController.tabBarController.tabBar.items objectAtIndex:0] setTitle:@"new title 1"];
[[self.parentViewController.tabBarController.tabBar.items objectAtIndex:1] setTitle:@"new title 2"];
[[self.parentViewController.tabBarController.tabBar.items objectAtIndex:2] setTitle:@"new title 3"];

编辑:因为它与在我之前发布的人看起来相同 Xp

You can explore on the IB or if you want to set it not in the appdelegate file you can use this:

[[self.parentViewController.tabBarController.tabBar.items objectAtIndex:0] setTitle:@"new title 1"];
[[self.parentViewController.tabBarController.tabBar.items objectAtIndex:1] setTitle:@"new title 2"];
[[self.parentViewController.tabBarController.tabBar.items objectAtIndex:2] setTitle:@"new title 3"];

edit: coz it looks the same from the person who posted before me Xp

惜醉颜 2024-12-29 10:49:05
 UITabBarItem *item = [self tabBarItem];
 item.title = @"Hi";
 UITabBarItem *item = [self tabBarItem];
 item.title = @"Hi";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文