繁体   English   中英

从SuperView中删除视图后显示特定的TabBarItem

[英]Show specific TabBarItem after view is removed from SuperView

HomeViewController-视图有2个图像按钮,分别称为“新”和“旧”。 这是我在TabBarController插入图片之前显示的初始视图。

点击“新建”时,我转到TabBarItem1。好,没问题。 * 当点击'Old'时,我想转到TabBarItem4。 *但是仍然转到TabBarItem 1。

这是我的代码如下所示:

在HomeViewController中,我有以下方法:

- (void) oldButtonPressed:(id)sender{
TabBarAppDelegate *allRootValues = [[UIApplication sharedApplication] delegate];
allRootValues.seeExistingClients = @"Y";
NSLog(@"old button pressed: see old clients: %@", allRootValues.seeExistingClients);

[self.view removeFromSuperview];
[self.tabBarController  setSelectedIndex:4];
}

AppDelegate:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:       (NSDictionary *)launchOptions
{
    // Override point for customization after application launch.


    HomeViewController *homeVC = [[HomeViewController  alloc]initWithNibName:@"HomeViewController" bundle:nil];  
    [self.window addSubview:homeVC.view];
    [self.window makeKeyAndVisible];

    seeExistingClients = @"N"; //Assigning to 'N' initially

    return YES;
  }

请检查以下情况,

 check the selected index which you are setting for selectedIndex:. The index for the controllers will be assigned from zero.

我认为这可能对您有用。

不要从HomeViewController删除self.view,不确定您的视图结构,但我认为HomeViewController是您的TabBarController一部分

因此,请执行以下操作

//[self.view removeFromSuperview];
[self.tabBarController  setSelectedIndex:3]; //3 size index starts from zero and you need the 4th controller

youca如下创建标签栏控制器对象,

 UITabBarController *tabBarController = [[UITabBarController alloc] init];

创建UITabBarController的对象后,为所有视图控制器创建引用。示例代码如下,

FirstViewController *fisrtCont = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
SecondViewController *secondCont = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];

创建实例后,将所有对象添加到数组。

NSArray *array = [[NSArray alloc] initWithObjects:fisrtCont, secondCont, nil];
tabBarController.viewControllers = array;

AppDelegate *delegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
[delegate.window setRootViewController:controller];

[tabBarController setSelectedIndex:3];

请检查一下,您是否按照所有步骤操作? 我在上面的代码中遵循了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM