2

UISplitViewControllers1つに複数を追加していUITabBarControllerます。タブが表示され、タブがクリックされると各マスター/子ビューコントローラーが正しく読み込まれて表示されますが、どういうわけかユーザー操作は最後に追加されたタブでのみ機能します。

1つのタブを追加すると正常に機能しますが、2つのタブを追加すると、2つ目のタブが機能し、1つ目のタブはユーザーインタラクションに応答しません(ユーザーインターフェイス要素をクリックしても何も起こりません。ハイライト表示されて表示されません。クリック)。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を設定した後、すべて(コントローラー、ナビゲーション、タブバーコントローラー)を解放してみてください。

于 2013-01-30T15:16:03.013 に答える