我添加了标签,但标签外的视图变得无法访问(ios)

Posted

技术标签:

【中文标题】我添加了标签,但标签外的视图变得无法访问(ios)【英文标题】:i added tabs but views outside tabs became unreachable (ios) 【发布时间】:2014-02-07 08:22:18 【问题描述】:

我的原始应用有 5 个主屏幕视图,主屏幕中的按钮可以打开不同的其他视图。

我没有使用故事板。最初应用程序中没有标签。然后我添加了标签来显示主屏幕使用

    UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil] ;
    UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
    UIViewController *viewController3 = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];
    UIViewController *viewController4 = [[FourthViewController alloc] initWithNibName:@"FourthViewController" bundle:nil];
    UIViewController *viewController5 = [[FifthViewController alloc] initWithNibName:@"FifthViewController" bundle:nil];

    UINavigationController *navigationController1=[[UINavigationController alloc]initWithRootViewController:viewController1];
    [navigationController1.navigationBar setBackgroundImage:[UIImage imageNamed:@"upwhitebg.png"] forBarMetrics:UIBarMetricsDefault];

    UINavigationController *navigationController2=[[UINavigationController alloc]initWithRootViewController:viewController2];
    [navigationController2.navigationBar setBackgroundImage:[UIImage imageNamed:@"upwhitebg.png"] forBarMetrics:UIBarMetricsDefault];

    UINavigationController *navigationController3=[[UINavigationController alloc]initWithRootViewController:viewController3];
    [navigationController3.navigationBar setBackgroundImage:[UIImage imageNamed:@"upwhitebg.png"] forBarMetrics:UIBarMetricsDefault];

    UINavigationController *navigationController4=[[UINavigationController alloc]initWithRootViewController:viewController4];
    [navigationController4.navigationBar setBackgroundImage:[UIImage imageNamed:@"upwhitebg.png"] forBarMetrics:UIBarMetricsDefault];

    UINavigationController *navigationController5=[[UINavigationController alloc]initWithRootViewController:viewController5];
    [navigationController5.navigationBar setBackgroundImage:[UIImage imageNamed:@"upwhitebg.png"] forBarMetrics:UIBarMetricsDefault];


     UITabBarController *tabBarController= [[UITabBarController alloc] init];
    tabBarController.viewControllers = @[navigationController1, navigationController2,navigationController3,navigationController4,navigationController5];
        //self.window.rootViewController = self.tabBarController;

    UIWindow *window = [[UIApplication sharedApplication] delegate].window;
    [window addSubview:tabBarController.view]

;

但是现在当我单击主屏幕上的按钮时,如何显示选项卡之外的视图?以及如何从该视图返回到 5 主屏幕选项卡视图。

之前我使用此代码显示按钮按下时的视图

 listController = [[MenuListController alloc] initWithNibName:@"MenuListController" bundle:nil];
    SUP101AppDelegate *delegate6 = [[UIApplication sharedApplication] delegate];
    [delegate6.navController pushViewController:listController animated:YES]

【问题讨论】:

【参考方案1】:

您现在只需在tabController 上显示其他视图控制器即可启动它们。

listController = [[MenuListController alloc] initWithNibName:@"MenuListController" bundle:nil];
SUP101AppDelegate *delegate6 = [[UIApplication sharedApplication] delegate];
[self.tabBarController presentViewController:listController animated:YES completion:nil];

您还应该将 tabController 设置为窗口 RootViewController

self.window.rootViewController = tabBarController;
//[window addSubview:tabBarController.view]

【讨论】:

只是补充一点,当您将根视图控制器设置为您的标签栏时,您不需要将标签栏视图添加为窗口的子视图。跨度>

以上是关于我添加了标签,但标签外的视图变得无法访问(ios)的主要内容,如果未能解决你的问题,请参考以下文章

访问 UIScrollView 中动态加载的标签

TabBar 按钮出现问题,TabBar 按钮变得不可点击

标签栏iOS xcode中心的按钮

如何向 UICollectionView 标头中的标签添加约束?

iOS视图不会显示标签和图像

为啥我的安卓手机在为自定义滚动视图添加标签栏视图后没有功能