-1

我有一个TabBar与2 viewControllers设置它,和mainScreen视图。我想要在应用程序启动时显示mainScreen视图 w/TabBar在底部,并且只有在TabBar被触摸时切换到TabBars viewControllers。UITabBar的帮助,请不要修复!

我的问题是TabBars viewController的视图将只显示,除非我设置TabBar的视图清除颜色,只有然后显示mainScreen视图。

回答

0

那么,你真的应该把你的applicationDidFinishLaunching代码在这里,以帮助我们了解你的目标。

所以,他们的想法是他们永远无法回到“mainScreen视图”?这有点奇怪,但我想你可以监视tabBar,当他们按下它时,你可以移除mainScreen。所以你的主应用程序代表看起来像这样:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController { 
    NSLog(@"tab pressed"); 
    [self.mainScreen removeFromSuperview]; 
    self.mainScreen = nil; 
} 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    //Build your tab controller here (or load in mainwindow.xib) 
    self.window.rootViewController = self.tabBarController; 
    self.tabBarController.delegate = self; 

    //now build your mainScreen (or get from mainwindow); for example... 
    self.mainScreen = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480-49)]; 
    self.mainScreen.backgroundColor = [UIColor blueColor]; 

    UIButton * temp = [[UIButton alloc] initWithFrame: CGRectMake(110, 60, 100, 20)]; 
    temp.backgroundColor = [UIColor redColor];  
    [mainScreen addSubview:temp]; 
    [temp release]; 

    //now put your mainscreen "over" your tabBar 
    [self.tabBarController.view addSubview:mainScreen]; 

    [self.window makeKeyAndVisible]; 

    return YES; 
} 
+0

是的,谢谢。这工作完美。这是我知道的一个奇怪的程序流程 – srome11 2011-02-16 09:53:22

0

我认为这意味着您的mainScreen视图低于层次结构中的TabBar视图。您可以将您的“mainScreen”视图添加为初始tabBar视图的子视图。

一旦用户与标签栏交互,您可以简单地删除您的mainScreen视图。在你的标签栏代表:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController { 
    if ([viewController.tabBarItem.title isEqualToString:@"TitleOfFirstViewInTabBar"]) { 
     [mainScreenView removeFromSuperview]; // Assuming mainScreenView is available 
    } 
}