我有一个由Interfacebuilder设置的UITabbarController。 tabbarcontroller有5个选项卡,第一个是欢迎页面,第二个是UITableViewController。两者都有一个NavigationController。第二个选项卡应显示类别列表。 当我启动应用程序时,一切都很好。当我按下第二个选项卡时,它会使用导航控制器完美地加载视图。 但我想要做的是能够使用第一个标签中的链接在第二个标签中加载某个类别。
所以我做的是在appDelegate中添加了以下函数,并且从第一个标签中的视图调用:
- (void)loadCategoryViewUsingCategoryId:(NSString*)categoryId
{
CategoryViewController *categoryView = [[CategoryViewController alloc] initWithLoadingCategoryUsingCategoryId:categoryId];
if (!categoryView) {
UIAlertView *errorView;
errorView = [[UIAlertView alloc]
initWithTitle: NSLocalizedString(@"Whoops", @"oddsAppAppDelegate")
message: NSLocalizedString(@"I did not found the requested category. Sorry!", @"oddsAppAppDelegate")
delegate: self
cancelButtonTitle: NSLocalizedString(@"Close", @"oddsAppAppDelegate") otherButtonTitles: nil];
[errorView show];
[errorView autorelease];
}
else {
self.tabBarController.selectedIndex = 1;
self.tabBarController.selectedViewController = categoryView;
[self.tabBarController.selectedViewController setTitle:@"apa"];
[self.tabBarController.selectedViewController viewDidLoad];
}
}
这很有效,但是......当加载第二个标签时,它没有导航控制器工具栏。如何加载它以便保留导航控制器工具栏?
顺便说一下,“CategoryViewController
”是UITableViewController
。
最好的问候,
保罗佩伦
答案 0 :(得分:1)
默认情况下,导航栏应可见。如果您想直接使用
访问它[[self navigationController] setNavigationBarHidden:NO];
我认为你的问题出在其他地方。如果您按照这样分配控制器
UITabBarController *theTabBar = [[UITabBarController alloc]init];
YourWelcomeViewClassHere *welcome = [[YourWelcomeViewClassHere alloc] initWithNibName:@"YourWelcomeViewClassHere" bundle:nil]; //Or other custom initalizers
UINavigationController *welcomeNav = [[UINavigationController alloc] initWithRootViewController:welcome];
CategoryViewController *category = [[CategoryViewController alloc] initWithNibName:@"CategoryViewController" bundle:nil]; //Or other custom initalizers
UINavigationController *categoryNav = [[UINavigationController alloc] initWithRootViewController:category];
/*
Your other View controllers initializations
*/
NSArray *viewControllers = [[NSArray alloc] initWithObjects:welcomeNav,categoryNav,/* other viewControllers ,*/nil];
[theTabBar setViewControllers:viewControllers];
这可能会起作用并显示您的观点。