我已經使用故事板構建了我的應用程序,並且所有視圖都由tabbarcontroller管理。在基於storyboard的應用程序中禁用/啓用UITabBarController中的選項卡
所以在啓動(我只工作目前iPad的UI),它這樣做:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
{
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UISplitViewController *splitViewController = [tabBarController.viewControllers objectAtIndex:0];
UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
splitViewController.delegate = (id)navigationController.topViewController;
UINavigationController *masterNavigationController = [splitViewController.viewControllers objectAtIndex:0];
ProductionMasterViewController *controller = (ProductionMasterViewController *)masterNavigationController.topViewController;
controller.managedObjectContext = self.managedObjectContext;
}
}
我希望能夠根據用戶輸入啓用或禁用tabBarController標籤(所以,例如,需要在第一個標籤中選擇一個項目才能訪問默認禁用的第二個和第三個標籤)
我不清楚的是如何訪問標籤以便啓用/消除它們。我想創建的appdelegate的一個實例,然後像做
AppDelegate *d = (AppDelegate *)[[UIApplication sharedApplication] delegate];
UITabBarController *tabs = (UITabBarController *)[d.window rootViewController];
[[[[tabs tabBar] items] objectAtIndex:2] setEnabled:YES];
[[[[tabs tabBar] items] objectAtIndex:3] setEnabled:YES];
[[[[tabs tabBar] items] objectAtIndex:4] setEnabled:YES];
(這有點兒好像它應該工作,但它似乎也相當噁心。)