0

我正在从 uiview 控制器添加一个 tabbarcontroller。请检查我的代码:

UITabBarController *tabBarController = [[UITabBarController alloc] init];
            NSMutableArray *arrControllers = [[NSMutableArray alloc] init];
            for(int i = 0; i<arrTabs.count;i++){
                NSArray *arr = [arrTabs objectAtIndex:i];
                if([[arr objectAtIndex:0] isEqualToString:@"PICS"]){
                    picTabViewController *pics = [[picTabViewController alloc] initWithNibName:@"picTabViewController" bundle:nil];
                    UINavigationController *picsNVC = [[UINavigationController alloc] initWithRootViewController:pics];
                    picsNVC.tabBarItem.image = [UIImage imageNamed:@"tab-news.png"];
                    picsNVC.tabBarItem.title = [arr objectAtIndex:1];
                    [arrControllers addObject:picsNVC];
                }
                if([[arr objectAtIndex:0] isEqualToString:@"MAP"]){
                    mapTabViewController *maps = [[mapTabViewController alloc] initWithNibName:@"mapTabViewController" bundle:nil];
                    UINavigationController *mapsNVC = [[UINavigationController alloc] initWithRootViewController:maps];
                    mapsNVC.tabBarItem.image = [UIImage imageNamed:@"tab-news.png"];
                    mapsNVC.tabBarItem.title = [arr objectAtIndex:1];
                    [arrControllers addObject:mapsNVC];
                }
                if([[arr objectAtIndex:0] isEqualToString:@"HTML"]){
                    htmlTabViewController *html = [[htmlTabViewController alloc] initWithNibName:@"htmlTabViewController" bundle:nil];
                    UINavigationController *htmlNVC = [[UINavigationController alloc] initWithRootViewController:html];
                    htmlNVC.tabBarItem.image = [UIImage imageNamed:@"tab-news.png"];
                    htmlNVC.tabBarItem.title = [arr objectAtIndex:1];
                    [arrControllers addObject:htmlNVC];
                }
            }
            tabBarController.viewControllers = arrControllers;
            self.tabBarController.selectedIndex = 0;
            [self.view.window addSubview:tabBarController.view];

根据需要添加选项卡栏控制器。但是现在我想添加一个按钮以返回上一页,或者您可以说从添加它的视图控制器中删除标签栏及其视图控制器。有人可以建议我怎么做吗?
请记住,我从 viewcontroller 添加了 tabbarcontroller 而不是 app delegate。

问候
潘卡伊

4

2 回答 2

0

只需将此方法放入AppDelegate.m文件中,当您想从超级视图中删除 tabbarcontroller 并将另一个视图设置为 parentviewController 时调用此方法

-(void)setMainView 
{

     yourViewController *masterViewController = [[[yourViewController alloc] initWithNibName:@"yourViewController" bundle:nil] autorelease];
     self.navigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
     self.navigationController.navigationBar.hidden=YES;
     self.window.rootViewController = self.navigationController;

    CATransition *animation = [CATransition animation];
    [animation setDelegate:self];   
    [animation setType:kCATransitionFade];
    [animation setDuration:0.5];
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:
                                  kCAMediaTimingFunctionEaseInEaseOut]];
    [[self.window layer] addAnimation:animation forKey:kAnimationKey];
}

并使用 AppDelegate 类的对象调用上述方法 For Ex..

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate setMainView];

我希望这对你有帮助..

于 2013-03-07T12:00:27.367 回答
0

我已经使用了一个 tabbar 和 alloc-init 一次,然后我将在不同UIView的 s 上显示和隐藏。
所以没有必要一直删除和分配。

显示标签栏

[self showTabBar:self.tabBarController];

隐藏标签栏

[self hideTabBar:self.tabBarController];

显示代码->通过设置'Y'会自动出现::

- (void) showTabBar:(UITabBarController *) tabbarcontroller
{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.4];
    for(UIView *view in tabbarcontroller.view.subviews)
    {
        if([view isKindOfClass:[UITabBar class]])
        {
            if ([[UIScreen mainScreen] bounds].size.height == 568)
            {
                [view setFrame:CGRectMake(view.frame.origin.x, 519, view.frame.size.width, view.frame.size.height)];
            }
            else if ([[UIScreen mainScreen] bounds].size.height == 480)
            {
                [view setFrame:CGRectMake(view.frame.origin.x, 431, view.frame.size.width, view.frame.size.height)];
            }
        }
        else
        {
            if ([[UIScreen mainScreen] bounds].size.height == 568)
            {
                [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 519)];
            }
            else if ([[UIScreen mainScreen] bounds].size.height == 480)
            {
                [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 431)];
            }
        }
    }
    [UIView commitAnimations];
}

隐藏代码 -> 它会通过设置它的'Y'自动消失::

- (void) hideTabBar:(UITabBarController *) tabbarcontroller
{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.4];
    for(UIView *view in tabbarcontroller.view.subviews)
    {
        if([view isKindOfClass:[UITabBar class]])
        {
            if ([[UIScreen mainScreen] bounds].size.height == 568)
            {
                [view setFrame:CGRectMake(view.frame.origin.x, 568, view.frame.size.width, view.frame.size.height)];
            }
            else if ([[UIScreen mainScreen] bounds].size.height == 480)
            {
                [view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)];
            }
        }
        else
        {
            if ([[UIScreen mainScreen] bounds].size.height == 568)
            {
                [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 568)];
            }
            else if ([[UIScreen mainScreen] bounds].size.height == 480)
            {
                [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
            }
        }
    }

    [UIView commitAnimations];
}

如果不想在申请期间一直分配和释放,希望它会对您有所帮助。
谢谢。

于 2013-03-07T11:02:03.067 回答