2

我将多个添加UISplitViewControllers到单个UITabBarController. 选项卡出现,每个主/子视图控制器在单击选项卡时加载并正确显示,不知何故,用户交互仅适用于添加的最后一个选项卡。

如果我添加 1 个选项卡,它工作正常,但如果我添加 2 个选项卡,第 2 个选项卡工作并且第一个选项卡不会响应用户交互(单击用户界面元素时没有任何反应 - 它们甚至不会突出显示点击)。如果我添加 3,则前 2 个中断,第 3 个有效。

我怎样才能解决这个问题?这是代码(注意:此方法在启动例程结束时从启动页面视图控制器调用):

- (void)startIPad 
{
    UINavigationController *localNavigationController;
    UISplitViewController *localSplitViewController;
    UITabBarController *tabBarController = [[UITabBarController alloc] init];
    NSMutableArray *localControllersArray = [[NSMutableArray alloc] init];

    //setup the first tab
    Master1ViewController *viewMaster1 = [[Master1ViewController alloc] init];
    Detail1ViewController *viewDetail1 = [[Detail1ViewController alloc] init];
    localNavigationController = [[UINavigationController alloc] initWithRootViewController:viewDetail1];
    localSplitViewController = [[UISplitViewController alloc] init];
    [localSplitViewController setDelegate:viewDetail1];
    localSplitViewController.viewControllers = [NSArray arrayWithObjects:viewMaster1, localNavigationController, nil];
    [localControllersArray addObject:localSplitViewController];
    [viewMaster1 release];
    [viewDetail1 release];
    [localNavigationController release];
    [localSplitViewController release];

    //setup the second tab
    Master2ViewController *viewMaster2 = [[Master2ViewController alloc] init];
    Detail2ViewController *viewDetail2 = [[Detail2ViewController alloc] init];
    localNavigationController = [[UINavigationController alloc] initWithRootViewController:viewDetail2];
    localSplitViewController = [[UISplitViewController alloc] init];
    [localSplitViewController setDelegate:viewDetail2];
    localSplitViewController.viewControllers = [NSArray arrayWithObjects:viewMaster2, localNavigationController, nil];
    [localControllersArray addObject:localSplitViewController];
    [viewMaster2 release];
    [viewDetail2 release];
    [localNavigationController release];
    [localSplitViewController release];

    //setup the third tab
    ...

    //setup the fourth tab
    ...

    //set the UISplitViewControllers onto the tab bar
    tabBarController.viewControllers = localControllersArray;
    [localControllersArray release];

    //switch to the new root view controller
    [appDelegate.window setRootViewController:tabBarController];
    [tabBarController release];
}
4

2 回答 2

4

我用你的代码创建了一个虚拟应用程序,它在我的应用程序中运行良好。只是我已经像这样初始化了appDelegate

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    //self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
    //self.window.rootViewController = self.viewController;
    [self startIPad];
    [self.window makeKeyAndVisible];
    return YES;
}



- (void)startIPad
{
    UINavigationController *localNavigationController;
    UISplitViewController *localSplitViewController;
    UITabBarController *tabBarController = [[UITabBarController alloc] init];
    NSMutableArray *localControllersArray = [[NSMutableArray alloc] init];

    //setup the first tab
    Master1ViewController *viewMaster1 = [[Master1ViewController alloc] init];
    Detail1ViewController *viewDetail1 = [[Detail1ViewController alloc] init];
    localNavigationController = [[UINavigationController alloc] initWithRootViewController:viewDetail1];
    localSplitViewController = [[UISplitViewController alloc] init];
    [localSplitViewController setDelegate:viewDetail1];
    localSplitViewController.viewControllers = [NSArray arrayWithObjects:viewMaster1, localNavigationController, nil];
    [localControllersArray addObject:localSplitViewController];
    [viewMaster1 release];
    [viewDetail1 release];
    [localNavigationController release];
    [localSplitViewController release];

    //setup the second tab
    Master2ViewController *viewMaster2 = [[Master2ViewController alloc] init];
    Detail2ViewController *viewDetail2 = [[Detail2ViewController alloc] init];
    localNavigationController = [[UINavigationController alloc] initWithRootViewController:viewDetail2];
    localSplitViewController = [[UISplitViewController alloc] init];
    [localSplitViewController setDelegate:viewDetail2];
    localSplitViewController.viewControllers = [NSArray arrayWithObjects:viewMaster2, localNavigationController, nil];
    [localControllersArray addObject:localSplitViewController];
    [viewMaster2 release];
    [viewDetail2 release];
    [localNavigationController release];
    [localSplitViewController release];

    //setup the third tab
   // ...

    //setup the fourth tab
    //...

    //set the UISplitViewControllers onto the tab bar
    tabBarController.viewControllers = localControllersArray;
    [localControllersArray release];

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

    //switch to the new root view controller
    [appDelegate.window setRootViewController:tabBarController];
    [tabBarController release];
}
于 2013-01-29T13:08:59.083 回答
0

在设置 window.rootviewcontroller 后尝试释放所有(控制器、导航、tabbarcontroller)。

于 2013-01-30T15:16:03.013 回答