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是一個故事板對象,所以沒有出口到標籤欄或任何東西。
在此先感謝!