おそらく簡単な質問ですが、私はそれに対する解決策を見つけるためにhellofaの時間を過ごしています。
タブバーコントローラーで現在のタブの識別子を見つけ、それを条件付きで使用してメソッドを実行する必要があります。
どうすればこれを見つけることができますか?
if (self.tabbarcontroller.identifier == @"My identifier") {
// do some method
} else {
// do the default method
}
おそらく簡単な質問ですが、私はそれに対する解決策を見つけるためにhellofaの時間を過ごしています。
タブバーコントローラーで現在のタブの識別子を見つけ、それを条件付きで使用してメソッドを実行する必要があります。
どうすればこれを見つけることができますか?
if (self.tabbarcontroller.identifier == @"My identifier") {
// do some method
} else {
// do the default method
}
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
UITabBarController *tabBarController = (UITabBarController*) window.rootViewController;
UIViewController *selectedVC = tabBarController.selectedViewController;
if ([selectedVC.identifier isEqualToString:@"anIdentifier"])
{
// Do something
} else {
// Do something else
}
ストーリーボードでViewControllerの識別子を設定できます
次のコードを確認してください。また、UITabBar のデリゲートが正しいビュー コントローラー (この場合は FirstViewController) を指していることを確認してください。
**FirstViewController.h****
@interface FirstViewController : UIViewController<UITabBarDelegate>
**FirstViewController.m:**
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
NSLog(@"%@",[item tag]);
}