プロジェクト内のもの: 1 つのタブ バー コントローラーと 4 つのビュー コントローラーを含むストーリーボード (つまり、4 つのタブ バー アイテムと 4 つのセグエがあり、非常に単純です) タブ バー コントローラーによって使用されるカスタム オブジェクト クラス、および「self.view」にボタンを描画します
問題は何ですか:「タブバーアイテムを押す」ことをシミュレートしたいのですが、機能していません。助けてください。(私は他にcustom-obj-classを持っていませんが、UITabBarController用の唯一のものです)私が試したこと:
[(UITabBarController*)self.navigationController.topViewController setSelectedIndex:3];
[self.tabBarController setSelectedIndex:3];
[self.tabBarController setSelectedController
[self.tabBarController setSelectedViewController:[self.tabBarController.viewControllers objectAtIndex:3]];
custom-obj-class.m :
- (IBAction)buttonPressed:(UIButton *)sender
{
if (self.tabBarController) {
NSLog(@"I have a tab bar");
[self.tabBarController setSelectedIndex:1];
} else {
NSLog(@"I don't have"); // I GOT THIS ONE
}
return;
}
- (void)viewDidLoad
{
[super viewDidLoad];
...
UIBarButtonItem *realRoomItem = [[UIBarButtonItem alloc] initWithImage:realRoomImage style:UIBarButtonItemStylePlain target:self action:@selector(buttonPressed:)];
...
}