UITabBar帮助,请不要修复!

时间:2011-02-16 05:18:07

标签: iphone objective-c uiviewcontroller uitabbarcontroller tabbar

我有一个TabBar,其中设置了2个viewControllers和一个mainScreen视图。我希望在应用程序启动时在底部显示带有TabBar的主屏幕视图,并且只有在触摸TabBar时才切换到TabBars viewControllers。

我的问题是TabBars viewController的视图只会显示,除非我将TabBar的视图设置为clearColor, only 然后显示mainScreen视图。

2 个答案:

答案 0 :(得分:0)

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

用户与标签栏交互后,您只需删除主屏幕视图即可。在标签栏委托:

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

答案 1 :(得分:0)

嗯,你真的应该把你的applicationDidFinishLaunching代码放在这里,以帮助我们理解你的目标。

那么,这个想法是他们永远无法回到“主屏幕视图”?这有点奇怪,但我想你可以监视tabBar,当他们按下它时,你删除了主屏幕。因此,您的主要应用代表看起来像:

- (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;
}