2011-03-10 76 views
2

我想要2個導航控制器附加到一個標籤欄項目。添加兩個導航控制器到一個標籤欄項目

基本上這個想法是在單個選項卡Item上有2個視圖,並且應該有一個導航欄來推送和彈出屏幕。 (與iPad中的設置應用程序相同)。

編輯======

它看起來像在左側有一個與自己的導航控制器,並在右側或視圖有其自己的導航控制器中的另一個視圖(其他一些UI)來實現Push Pop的東西。

我知道如何將1個導航控制器連接到一個選項卡欄項目。

爲ModalView編輯問題: - 通過執行conmulligan代碼一切工作屬性。但是,如果我嘗試在lansdscape模式下顯示一些ModalViewController,並且當我嘗試關閉此ModalView時,FirstViewController導航欄變爲縱向(及其視圖),並且SecondViewController NavigationBar保持橫向(應該是)。這隻發生在設備不在模擬器中。

下面是我介紹ModalViewController的代碼。

ModalTableViewController *modalTableViewController = [[ModalTableViewController alloc]initWithNibName:@"ModalTableViewController" bundle:[NSBundle mainBundle]]; 
UINavigationController *localNavigationViewController = [[UINavigationController alloc] initWithRootViewController:modalTableViewController]; 
localNavigationViewController.modalPresentationStyle = UIModalPresentationFormSheet; 
[self presentModalViewController:localNavigationViewController animated:YES]; 
[modalTableViewController release]; 
[localNavigationViewController release]; 

對於Dismising的ModalViewCntroller我做如下: -

[self dismissModalViewControllerAnimated:YES]; 

等待您的答覆。 enter image description here

回答

4

一種方法是創建一個UIViewController子類,其中包含兩個導航控制器並將其添加到UITabBarController。下面是你在UIViewController-viewDidLoad方法來創建和佈局的導航控制器:

FirstViewController *firstViewController = [[FirstViewController alloc] init]; 
UINavigationController *firstNavigationController = [[UINavigationController alloc] initWithRootViewController:firstViewController]; 
[firstViewController release]; 

SecondViewController *secondViewController = [[SecondViewController alloc] init]; 
UINavigationController *secondNavigationController = [[UINavigationController alloc] initWithRootViewController:secondViewController]; 
[secondViewController release]; 

firstNavigationController.view.frame = CGRectMake(0.f, 0.f, 320.f, self.view.frame.size.height); 
firstNavigationController.view.autoresizingMask = UIViewAutoresizingFlexibleHeight; 

secondNavigationController.view.frame = CGRectMake(321.f, 0.f, self.view.frame.size.width - 321.f, self.view.frame.size.height); 
secondNavigationController.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth | 
                UIViewAutoresizingFlexibleRightMargin; 

[self.view addSubview:firstNavigationController.view]; 
[self.view addSubview:secondNavigationController.view]; 

這或多或少是如何引擎蓋下的UISplitViewController作品。

編輯:您可能需要添加以下代碼,以確保它正確地勾畫出:

- (void)viewWillAppear:(BOOL)animated { 
    [super viewWillAppear:animated]; 
    [firstNavigationController viewWillAppear:animated]; 
    [secondNavigationController viewWillAppear:animated]; 
} 

- (void)viewWillDisappear:(BOOL)animated { 
    [super viewWillDisappear:animated]; 
    [firstNavigationController viewWillDisappear:animated]; 
    [secondNavigationController viewWillDisappear:animated]; 
} 

- (void)viewDidAppear:(BOOL)animated { 
    [super viewDidAppear:animated]; 
    [firstNavigationController viewDidAppear:animated]; 
    [secondNavigationController viewDidAppear:animated]; 
} 

- (void)viewDidDisappear:(BOOL)animated { 
    [super viewDidDisappear:animated]; 
    [firstNavigationController viewDidDisappear:animated]; 
    [secondNavigationController viewDidDisappear:animated]; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    return YES; 
} 
+0

- 感謝您的回覆。如果我嘗試以橫向模式啓動應用程序,則無法從您的代碼中查看這兩個視圖。我能夠看到只有一個視圖是secondViewController。你能幫我解決這個問題嗎? – Ekra 2011-03-14 10:54:02

+0

嗨@Ekra,這很奇怪,它適合我。嘗試在上面的'UIViewController'子類中添加額外的代碼。 – conmulligan 2011-03-14 14:55:50

+0

- 感謝您的回覆。我有一些顯示ModalView的問題,我已經在上面解釋過了。請看看它。等待你的回覆。 – Ekra 2011-03-30 12:24:12

相關問題