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