0

我想與另一個UINavigationViewController和UIViewController子類創建UITabBarViewController的主屏幕。當與UITabBarController結合UINavigationBar顯示不正確

在實際應用中,主要有:

  • 兩個製表裝載NewsController和視頻控制器
  • HomeViewController加載應用程序完成啓動後立即時。

這是我的應用程序拍攝畫面。

HomeViewController enter image description here

導航欄有半

NewsViewController enter image description here

這是我的代碼。

//在TabBarWithHomeDelegate.m

- (BOOL)application:(UIApplication *)application 
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 

    homeViewController = [[HomeViewController alloc]init]; 

    UINavigationController *nav = [[UINavigationController alloc]init]; 

    nav.navigationItem.title = @"Tab 1 Data"; 
    [nav pushViewController:homeViewController animated:NO]; 


    [self.tabBarController setSelectedViewController:nav]; 

    self.window.rootViewController = self.tabBarController; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 

//在NewsViewController.m對home鍵

-(IBAction) homeButtonClick:(id)sender 
{ 
     TabBarWithHomeAppDelegate * appDelegate 
     = [[UIApplication sharedApplication] delegate]; 

     UITabBarController * tabBarController = appDelegate.tabBarController; 
     [tabBarController setSelectedViewController:nil]; 
     [tabBarController setSelectedViewController:appDelegate.homeViewController]; 

} 

觸摸此外,我附上源代碼。如果你看到並且幫助我解決這個問題,我將會畢業。事實上,我嘗試自己做了近6個小時。

link to download source code.

回答

1

你HomeViewController未被指定爲在您的UITabBarController一個標籤,所以你不應該叫:

[tabBarController setSelectedViewController:appDelegate.homeViewController]; 

你應該讓它成爲一個真正的標籤或做一些不同的事情。我建議叫

[tabBarController presentModalViewController:homeViewController animated:YES]; 

您將無法看到標籤欄在這種情況下,所以你需要一個不同的方法來關閉該homeViewController。但是,這樣做更爲正確,因爲用戶無法看到當前未選中選項卡的選項卡欄控制器。

+0

嗨塞巴斯蒂安塞利斯, 非常感謝。不幸的是,將presentModalViewController設置爲您的建議,HomeViewController不會顯示在屏幕頂部。 :) – embarus

+0

它應該。確保您正確調用它並閱讀presentModalViewController文檔。 –

+0

它現在可以工作,非常感謝,但是我怎樣才能控制在nib中定義的HomeViewController中的視圖大小。當它加載到tabBarController的模式時,它總是填充到全屏幕大小。我想要在屏幕底部顯示tabbar。 – embarus

0

我只是評論你的代碼中- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions和所有完美的作品:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window.rootViewController = self.tabBarController; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 
+0

Hi Nekto, 非常感謝。但是,我想要在屏幕上顯示HomeviewController的內容。它顯示應用程序啓動和觸摸主頁按鈕的時間。 – embarus

+0

你用我的代碼試試嗎?它顯示你到底想要什麼 – Nekto

+0

是的,我喜歡。 :)我想我沒有說清楚。 我需要顯示在UITabBarContrller上的HomeViewController。 啓動應用程序後,它會顯示帶有兩個加載其他視圖控制器的選項卡的主屏幕。 – embarus