Tôi đã xây dựng ứng dụng của mình với bảng phân cảnh và tất cả các chế độ xem được quản lý bởi một thanh điều khiển tabbar.Vô hiệu/Bật các tab trong UITabBarController trong ứng dụng dựa trên kịch bản
Vì vậy, trên mắt (tôi chỉ làm việc trên iPad UI hiện tại) nó thực hiện điều này:
- (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;
}
}
Tôi muốn để có thể kích hoạt hoặc vô hiệu hóa các tab trong tabBarController dựa trên người dùng nhập vào (vì vậy ví dụ: một mục cần phải được chọn trong tab đầu tiên để truy cập tab thứ hai và thứ ba, được tắt theo mặc định)
Điều tôi không rõ là cách truy cập các tab để cho phép/giải quyết chúng. Tôi sẽ tạo ra một thể hiện của các appdelegate và sau đó làm một cái gì đó giống như
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];
(Đó là kinda có vẻ như nó sẽ làm việc nhưng nó cũng có vẻ khá thô thiển.)