【问题标题】:Viewcontrollers loses interactivity after adding it to tabbarcontrollerViewcontrollers 添加到 tabbarcontroller 后失去交互性
【发布时间】:2023-03-10 20:10:01
【问题描述】:

我以编程方式添加了 tabbarcontroller,然后向其中添加了两个视图控制器。相同的代码是:

ExampleViewcontroller.m

self.tabController = [[UITabBarController alloc] init];

viewController1 =[[invoiceviewcontrolleralloc]
initWithNibName:@"invoiceviewcontroller" bundle:nil];

viewController1.title = @"Unpaid Invoice";

viewController2=[[remittanceviewcontrolleralloc]
initWithNibName:@"remittanceviewcontroller" bundle:nil];

tabController.view.frame = CGRectMake(0, 0, 320, 460);

self.tabController.viewControllers = [NSArray arrayWithObjects:
viewController1,viewController2,nil];

[self.view addSubview:tabController.view]; 
tabController.delegate=self;

self.view bringSubviewToFront:tabController.view];

而tabbarcontroller的方法如下:-

-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:
(UIViewController *)viewController
{

if(tabController.selectedIndex==0)
{
[viewController2.view removeFromSuperview];

[self.view addSubview:viewController1.view];
}

else  if(tabController.selectedIndex==1)
{    
[viewController1.view removeFromSuperview];

[self.view addSubview:viewController2.view];
}

[self.view bringSubviewToFront:tabController.view];
}

代码运行良好,但当我单击第二个选项卡时,viewcontroller 附加到失去交互性,即其中的功能不响应单击。

【问题讨论】:

    标签: ios uiviewcontroller uitabbarcontroller non-interactive


    【解决方案1】:

    UITabBarController 旨在位于 UIVIewController 层次结构的顶部,或直接以模态方式呈现。你不能把它的视图放在你的 UIViewControllers 的另一个视图中,并期望它正常工作。事实上,每当您发现自己手动将一个视图控制器的视图添加到另一个视图控制器时,您可能做错了。如果您使用得当,视图控制器将为您处理这些工作。

    请在此处阅读“创建标签栏界面”并特别注意要点:http://developer.apple.com/library/ios/ipad/#documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/TabBarControllers.html#//apple_ref/doc/uid/TP40011313-CH3

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-20
      • 1970-01-01
      • 2016-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多