更改故事板后,不会调用Tabbar委托方法

我在登录故事板中登录注册 viewcontrollers不在主故事板中。

一旦注册或登录成功,我就会将Login storyboard更改为Main。 以下代码有效但当我选择任何选项卡时,它不会在AppDelegate中调用tab delegate方法

但是,如果用户已成功注册或登录,则会调用以下tabbar委托方法。

LoginViewController.m

if(isLoginSuccess) { UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; CustomTabBarViewController *tbc = [mainStoryboard instantiateViewControllerWithIdentifier:@"tabbar"]; tbc.selectedIndex = 2; [self presentViewController:tbc animated:YES completion:nil]; } 

AppDeletage.m

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { CustomTabBarViewController *tabBarController = (CustomTabBarViewController *)self.window.rootViewController; tabBarController.delegate = self; return YES; } -(void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController { if (tabBarController.selectedIndex == 2) { if(![self isRegistered]) { UIStoryboard *loginStoryboard = [UIStoryboard storyboardWithName:@"LoginStoryboard" bundle:nil]; UIViewController *vc = [loginStoryboard instantiateViewControllerWithIdentifier:@"LoginViewController"]; [ROOTVIEW presentViewController:vc animated:YES completion:nil]; } else { tabBarController.selectedIndex = 2; } } } 

更新:

AppDelegate没有被调用,但我想知道为什么以下代码在用户注销后没有在AppDelegate中打开Loginstoryboard。

 #define ROOTVIEW [[[UIApplication sharedApplication] keyWindow] rootViewController] UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"LoginStoryboard" bundle:nil]; UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"LoginViewController"]; [ROOTVIEW presentViewController:vc animated:YES completion:nil]; 

请在下面找到代码。

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { UIStoryboard *main = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; UITabBarController *tabController = [main instantiateViewControllerWithIdentifier:@"TabbarController"]; tabController.delegate = self; return YES; } -(void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{ NSLog(@"Selected Index - %lu",(unsigned long)tabBarController.selectedIndex); } 

在ViewController的Button Click方法中,

 - (IBAction)btnLoginTapped:(id)sender { UIStoryboard *main = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; UITabBarController *tabController = [main instantiateViewControllerWithIdentifier:@"TabbarController"]; tabController.selectedIndex = 1; [self presentViewController:tabController animated:YES completion:nil]; } 

然后在Main.storyboard上 ,从对象库拖动对象并将其放在标签栏控制器场景中的第一响应者下面,将对象类设置为AppDelegate ,然后右键单击选项卡栏控制器并将委托设置为该对象类 ,如下图所示。

在此处输入图像描述

让我知道它是否有效,我已准备好帮助解决方案了。