12

初心者の質問で申し訳ありません。メイン ウィンドウ ビューに UITabBar と、各タブの UINavigationControllers の配列があります。この構造は、TabBar アイテムを選択することでメイン ビューを表示できるという点で iPod アプリに似ており、ユーザーはビューをスタックにプッシュすることで、NavigationController を使用してさらにドリルダウンできます。

私ができるようにしたいのは、コード内のサブビューの下部にある TabBar ボタンを押すのと同じことを行うことです (つまり、TabBar の選択されたプロパティを変更し、タブの最初のビュー コントローラーを起動して表示します)。 .

どんな助けでも大歓迎です。

デイブ

4

6 に答える 6

23
[myTabBarController setSelectedIndex:index]

編集:コメントからパート2の質問に答える:

別のタブに切り替えるためのメソッドをAppDelegateで定義できます。

そして、あなたはどこからでもappdelegateを手に入れて、メッセージを送ることができます。

 MyAppDelegate *appDelegate = (MyAppDelegate*) [[UIApplication sharedApplication] delegate];
 [appDelegate SwitchToTab:index]
于 2009-11-25T08:32:16.147 に答える
11

あるいは...

[self.parentViewController.tabBarController setSelectedIndex:3];
于 2010-06-10T19:41:02.670 に答える
3

プラカシュに返信したいのですが、どうすればいいのかわかりません。スコアが上がるまでブロックされているのかもしれません。

とにかく、これが誰かに役立つことを願っています:

私はプラカシュが言ったことをやっていたが、何も起こらなかった。これは、アプリデリゲートへのポインターを取得するために、次のことを行っていたためです。

AppDelegate_Phone *appDelegate = [[AppDelegate_Phone alloc] init];

私がこれをすべきだったとき:

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

初心者の間違い。

于 2010-07-03T06:05:35.670 に答える
0
[self.parentViewController.tabBarController setSelectedIndex:3];

私のためにインデックスを選択しましたが、navbarcontroller のインデックスをアクティブなインデックスとして強調表示しましたが、そのインデックスを強調表示している間、実際には tabbarmenu 項目によって提案されたものとは異なるビューコントローラーにありました。

ビューコントローラーからこれを使用したことを追加したかっただけで、誰かが実際にメニュー項目を押したように動作しました。コードから:

UITabBarController *MyTabController = (UITabBarController *)((AppDelegate*) [[UIApplication sharedApplication] delegate]).window.rootViewController;
[MyTabController setSelectedIndex:1];

私のプロジェクトで大いに役立ったこの投稿/回答に感謝します。

于 2012-06-15T23:20:03.390 に答える
0

このためには、 UITabBar コントローラーを使用するだけです-

.h ファイル -

UITabBarController *_pTabBarController;
@property (nonatomic, retain) IBOutlet  UITabBarController *_pTabBarController;

.m File -
// synthesize it 
@synthesize  _pTabBarController;    

At initial load 

// You can  write one function to add tabBar - 

// As you have already mentioned you have created an array , if not 

_pTabBarController = [[UITabBarController alloc] init];
    NSMutableArray *localViewControllersArray = [[NSMutableArray alloc] initWithCapacity:4];
    UINavigationController *theNavigationController;

    _pController = [[Controller alloc] initStart];  
    _pController.tabBarItem.tag = 1;
    _pController.title = @"Baranches";
    theNavigationController = [[UINavigationController alloc] initWithRootViewController:_pController];
    theNavigationController.tabBarItem.tag = 1;
    theNavigationController.tabBarItem.image = [UIImage imageNamed:@"icon_branches.png"];
    [localViewControllersArray addObject:theNavigationController];
    [theNavigationController release];

必要に応じてインデックスを設定できるよりも

self._pTabBarController.selectedIndex = 0; // as per your requirements
于 2011-10-12T07:19:40.837 に答える
0

私は似たようなことをしたかったのですが、XCode 6.4 iOS (8.4) setSelectedIndex だけではできません。

タブ バーのビュー コントローラーをリストに追加し、関数で次のようなものを使用して呼び出します。

FirstViewController *firstVC = [[self viewControllers] objectAtIndex:0];
[self.selectedViewController.view removeFromSuperview]
[self.view insertSubview:firstVC.view belowSubview:self.tabBar];
[self.tabBar setSelectedItem:self.firstTabBarItem];
self.selectedViewController = firstVC;

didSelectedItem 内に既に同様のコードがあるかもしれません。

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {

   if (item == self.firstTabBarItem) 
      // Right here
    }
    else if ...
}
于 2015-07-29T19:31:04.483 に答える