标签栏项目标题以编程方式不显示在目标c中
我尝试以编程方式创建标签栏控制器,它的工作原理,但我无法将标题设置为ta栏项目。当我运行我的应用程序时,我看不到标题。我的代码在这里。请帮助我,这是什么问题?标签栏项目标题以编程方式不显示在目标c中
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
myTabBarController = [[UITabBarController alloc] init];
view2Controller = [[testView alloc] init];
view3Controller = [[testView2 alloc] init];
view4Controller = [[testView3 alloc] init];
view5Controller = [[testView4 alloc] init];
view6Controller = [[testView5 alloc] init];
myTabBarController.viewControllers = [NSArray arrayWithObjects: view2Controller, view3Controller,view4Controller,view5Controller,view6Controller,nil];
UITabBarItem *tabItem = [[[myTabBarController tabBar] items] objectAtIndex:1];
[tabItem setTitle:@"theTitle"];
[self.view addSubview:myTabBarController.view];
myTabBarController.selectedIndex=0;
}
您可以设置标题UIViewController
,该标题反映的是UINavigationController
或UITabBarController
的推送时间。但是你应该在将标题放入其中之前设置标题。
init
通常是设置标题的好地方。
- (id)init {
// ... other code including check for self
self.title = @"My Title";
return self;
}
我试试这个 - (id)initWithTabBar {(self init)){ self.title = @“tab1dir”; } return self; }但是没有工作:S – 2012-01-16 09:46:49
另外我尝试 - (id)i nit {...}其他代码,包括自我检查 self.title = @“My Title”; 回归自我; }但仍无法使用 – 2012-01-16 09:48:44
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// self.title = @"My Title";
}
self.title = @"My Title";
return self;
}
在的TabBar控制器的每一个的子视图使用上述代码。
这可能有所帮助。
use this code
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
[email protected]"FREE BOOKS";
self.tabBarItem.image = [UIImage imageNamed:@"first"];
}
return self;
}
我试试这个,但不行还是:( – 2012-01-16 09:39:27
我在'viewDidLoad'设置它,但它没有工作,但在'viewWillAppear中:'运行良好感谢 – Gonzo 2015-03-06 21:52:48