2010-08-21 54 views
1

我有一個由Interfacebuilder設置的UITabbarController。 tabbarcontroller有5個選項卡,第一個是歡迎頁面,第二個是UITableViewController。兩者都有一個NavigationController。第二個標籤應該顯示一個分類列表。 當我啓動應用程序時,一切都很好。當我按第二個選項卡時,它會使用導航控制器完美加載視圖。 但我想要做的是能夠使用第一個選項卡中的鏈接在第二個選項卡中加載某個類別。UITabbarController設置視圖

所以我所做的就是我在的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

最好的問候,
保羅Peelen

回答

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]; 

這可能會工作並顯示您的意見。

+0

嗨, 我試過了,但它不適合我。然後,你的帖子開始思考並給了我以下解決方案: \t \t self.tabBarController.selectedIndex = 1; \t \t UINavigationController * nav = [self.tabBarController.viewControllers objectAtIndex:1]; \t \t nav.viewControllers = [[NSArray alloc] initWithObjects:categoryView,nil]; 這對我有用。 Regards, Paul Peelen – 2010-08-21 12:45:44

相關問題