问题描述
- uitabbar controller中标题显示的问题
- 使用以下代码创建了uitabbarview controller
在uitabbarview controller中我想为每一个视图显示标题
怎么样为每个视图添加标题呢(标题栏项目)?myTabBarController = [[UITabBarController alloc] init]; MyDialerViewController *aDialerViewController = [[MyDialerViewController alloc]init]; MyCallLogViewController *aCallLogViewController = [[MyCallLogViewController alloc] init]; TemplateViewController *aTemplateViewController = [[TemplateViewController alloc] init]; NSArray* controllers = [NSArray arrayWithObjects:aDialerViewController aCallLogViewController aTemplateViewController nil]; myTabBarController.viewControllers = controllers; myTabBarController.delegate = self; myTabBarController.selectedIndex = 0; [controllers release]; [aDialerViewController release]; [aCallLogViewController release]; [aTemplateViewController release]; [self.window addSubview:myTabBarController.view]; [self.window makeKeyAndVisible];
解决方案
在appDelegate里面直接设置navcontroller的标题。同时也在viewcontroller里面的viewDidLoad 中设置。
aDialerViewController.title = NSLocalizedString(@""Dialer Title"" @""Dialer Title"");aCallLogViewController.title = @""Title"";aTemplateViewController.title = @""Title"";
解决方案二:
self.viewcontroller.tabBarItem = // a UITabBarItem instance
给UITabBarItem实例化一个实例。
要在每一个 viewcontroller的初始化函数里写入:
(id)initWithTitle:(NSString *)title image:(UIImage *)image tag:(NSInteger)tag
时间: 2024-11-08 19:02:24