0

HomeViewController - ビューには「New」と「Old」という 2 つの画像ボタンがあります。これは、TabBarController が開始される前に表示する開始ビューです。

[New] をタップすると、TabBarItem 1 に移動します。問題ありません。* 「Old」をタップしたら、TabBarItem 4 に移動したい。 * それでも、TabBarItem 1 に移動します。

これは私のコードがどのように見えるかです:

HomeViewController には、次のメソッドがあります。

- (void) oldButtonPressed:(id)sender{
TabBarAppDelegate *allRootValues = [[UIApplication sharedApplication] delegate];
allRootValues.seeExistingClients = @"Y";
NSLog(@"old button pressed: see old clients: %@", allRootValues.seeExistingClients);

[self.view removeFromSuperview];
[self.tabBarController  setSelectedIndex:4];
}

AppDelegate:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:       (NSDictionary *)launchOptions
{
    // Override point for customization after application launch.


    HomeViewController *homeVC = [[HomeViewController  alloc]initWithNibName:@"HomeViewController" bundle:nil];  
    [self.window addSubview:homeVC.view];
    [self.window makeKeyAndVisible];

    seeExistingClients = @"N"; //Assigning to 'N' initially

    return YES;
  }
4

3 に答える 3

0

からself.viewを削除しHomeViewControllerないでください、ビューの構造についてはよくわかりませんが、それはあなたHomeViewControllerの一部であると思いますTabBarController

したがって、次のようにします

//[self.view removeFromSuperview];
[self.tabBarController  setSelectedIndex:3]; //3 size index starts from zero and you need the 4th controller
于 2012-06-27T11:32:10.337 に答える
0

次のシナリオを確認してください。

 check the selected index which you are setting for selectedIndex:. The index for the controllers will be assigned from zero.

これはあなたに役立つかもしれないと思います。

于 2012-06-27T11:28:12.993 に答える
0

次のようにタブ バー コントローラー オブジェクトを作成します。

 UITabBarController *tabBarController = [[UITabBarController alloc] init];

UITabBarController のオブジェクトを作成した後、すべてのビュー コントローラーの参照を作成します。コード例は次のとおりです。

FirstViewController *fisrtCont = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
SecondViewController *secondCont = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];

インスタンスを作成したら、すべてのオブジェクトを配列に追加します。

NSArray *array = [[NSArray alloc] initWithObjects:fisrtCont, secondCont, nil];
tabBarController.viewControllers = array;

AppDelegate *delegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
[delegate.window setRootViewController:controller];

[tabBarController setSelectedIndex:3];

これを確認してください。すべての手順に従っていますか? 上記のコードに従っています。

于 2012-06-27T12:13:02.780 に答える