我想通过编程方式创建一个标签栏控制器和导航控制器。到目前为止,我的代码可以在底部显示一个选项卡栏,但第二个选项卡栏上的OptionViewController按钮没有任何标题。有趣的是,当我点击没有任何东西的按钮时,标题就会出现(并且他的视图也是如此),有人能解释一下我做错了什么吗?我尝试使用以下代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[self.window makeKeyAndVisible];
NSMutableArray *tabItems = [[NSMutableArray alloc] initWithCapacity:2];
DefaultViewController *dvc = [[DefaultViewController alloc] init];
UINavigationController *dvc_nc = [[UINavigationController alloc] initWithRootViewController:dvc];
[tabItems addObject:dvc_nc];
[dvc release];
[dvc_nc release];
OptionsViewController *ovc = [[OptionsViewController alloc] initWithStyle:UITableViewStyleGrouped];
UINavigationController *ovc_nc = [[UINavigationController alloc] initWithRootViewController:ovc];
[tabItems addObject:ovc_nc];
[ovc release];
[ovc_nc release];
UITabBarController *tbc = [[UITabBarController alloc] init];
tbc.viewControllers = tabItems;
self.tabController = tbc;
[tabItems release];
[tbc release];
[self.window addSubview:self.tabController.view];
return YES;
}
OptionsViewConbtroller
的title
?如果你没有在init
方法中设置标题,那么 TabBarController 只会从 OptionsVC 中读取一个空标题。我猜你是在viewDidLoad
等方法中设置了标题属性? - thomas