2012-05-01 69 views
0

在prepareForSegue期间,是否可以修改父视图控制器中的标签栏项目?基本上,我试图在父控制器中插入逻辑,其中2个可能的标签栏项中的一个可能在继续移除时被删除。在父视图控制器中修改标签栏项目

我试图沿着线的东西:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    if ([segue.identifier isEqualToString:@"identifierOfInterest"]) { 
     UITabBarController *tabBarController = (UITabBarController *)segue.destinationViewController; 

     // Attempt 1 
     NSMutableArray *items = [[tabBarController.tabBar items] mutableCopy]; 
     [items removeObjectAtIndex:1]; 
     [tabBarController.tabBar setItems:items animated:YES]; 

     // Attempt 2 
     NSMutableArray *items = [[tabBarController viewControllers] mutableCopy]; 
     [items removeObjectAtIndex:1]; 
     [tabBarController setViewControllers:items]; 
    } 
} 

不幸的是这两条消息崩溃与以下错误应用程序:

尝试1:

Directly modifying a tab bar managed by a tab bar controller is not allowed. 

尝试2:

[UITabBarItem parentViewController]: unrecognized selector sent to instance 

我正在使用Xcode 4.2,iOS 5与UI Tab Bar Controller是一个故事板对象,所以没有出口到标签栏或任何东西。

在此先感谢!

回答

0

通常在TabBar应用程序中,AppDelegate拥有(或有参考)选项卡栏控制器,因为它是“主”视图控制器。你不能使用标签栏视图控制器,或者至少你不应该。如果您需要让应用程序的标签栏控制器执行某些操作,请将消息发送到应用程序委托实例,该实例应具有对选项卡栏控制器的引用以执行该工作。

​​
相关问题