0

我以编程方式添加了 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 附加到失去交互性,即其中的功能不响应单击。

4

1 回答 1

0

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

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

于 2012-04-21T17:12:40.677 回答