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