簡體   English   中英

將ViewController添加到TabbarController后失去交互性

[英]Viewcontrollers loses interactivity after adding it to tabbarcontroller

我已經以編程方式添加了tabbarcontroller,然后向其中添加了兩個viewcontrollers。相同的代碼是:

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];
}

該代碼運行良好,但是當我單擊視圖控制器附加到的第二個選項卡時,它失去了交互性,即其中的功能無法響應單擊。

UITabBarController旨在位於UIVIewController層次結構的頂部,或以模態直接顯示。 您不能將其視圖放在UIViewControllers的另一個視圖中,並且不能期望它正常工作。 實際上,每當您發現手動將一個視圖控制器的視圖添加到另一個視圖控制器時,您可能就在做錯了。 如果您適當地使用它們,則視圖控制器將為您完成此操作。

請閱讀此處的“創建選項卡欄界面”,並特別注意以下要點: http : //developer.apple.com/library/ios/ipad/#documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/TabBarControllers.html# // apple_ref / doc / uid / TP40011313-CH3

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM