uitabbaritemの強調表示された状態をプログラム的に変更 - 目的c
-
29-09-2019 - |
質問
プログラムでそうすることを選択したときに、UITABBARITEMを強調表示する方法を知りたいと思います。これは可能ですか?
ありがとう
解決
選択したタブを変更できます - ハイライトも変更します - 簡単に:
tabcontroller.selectedIndex = youNewIndexHere;
TabControllerがアプリデリゲートにある場合(プロジェクトを作成したときにTab Barアプリケーションテンプレートを使用した場合はそうです)、次のようになります。
ProjectNameAppDelegate *appDelegate = (ProjectNameAppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate tabcontroller].selectedIndex = youNewIndexHere;
他のヒント
Tabbarは、インデックスを知っていて、次のように書くと機能します。
NSMutableArray *item [[NSMutableArray alloc] init];
[items addObject: [[[UITabBarItem alloc] initAsULike] autorelease]; <--- init as you like here
...
[tabBar setItems:items animated:FALSE];
tabBar.selectedItem = [items objectAtIndex: your_index]; <--- write your index here
[items release];
IBで作成されたが、TabbarControllerはありません。 Awakefromnibでは、このような最初のアイテムに初期化するだけです。
[self.tabBar setSelectedItem:[[self.tabBar items] objectAtIndex:0]];
忘れないでください、uitabbardelegate didselectititemは、この場合に呼び出されません。
所属していません StackOverflow