57

我在 UIViewController 中为我的一个选项卡执行此操作:

self.title = @"Welcome";

但是,它覆盖了我对 tabBarItem 的所有内容。我努力了:

self.tabBarItem.title = @"Home";

[self.tabBarItem initWithTitle:@"Home" image:[UIImage imageNamed:@"iconHome.png"] tag:0];

但是,self.title 仍然会覆盖 tabBarItem,无论我是否在设置标题后尝试后两段代码。代码甚至可以毫无错误地运行,但是self.tabBarItem.titleorinitWithTitle没有做任何事情?

4

4 回答 4

171

好的,我想通了!这就是我正在做的事情:

self.title = @"Title for TabBarItem"; // TabBarItem.title inherits the viewController's self.title
self.navigationItem.title = @"Title for NavigationBar";

navigationBar继承 self.title,除非另外设置使用self.navigationItem.title

于 2009-10-20T17:54:44.330 回答
59
//set nav item title
self.navigationController.navigationBar.topItem.title = @"zurück";

这对我来说是这样的:=) (以上都不起作用)

于 2011-03-14T12:28:32.337 回答
0

尝试:

[self setTitle:@"Welcome"];

UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:@"Home" image:[UIImage imageNamed: image] tag:0];
[self setTabBarItem:item];
[item release];
于 2009-10-08T22:17:56.777 回答
0

我也面临同样的问题,但我这样解决这个问题。我在 appDelegate 中创建 tabBarItem 后立即设置它们的标题和图像。

这就是我所做的:

[viewController setTitle:@"controllerTitle"];
[[viewController tabBarItem] setTitle:@"Custome Title for tab"];
[[viewController tabBarItem] setImage:[UIImage imageNamed:@"tab.png"]];
于 2010-08-30T17:41:57.973 回答