我正在开发聊天应用程序,并且在成功登录后,我想推送控制器并向用户显示标签栏。
以下是我用过它的代码
这是我的 TabBarViewCtr
appdel=(TabBarAppDelegate *)[[UIApplication sharedApplication]delegate];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
nextFirstViewCtr = [[FirstViewCtr alloc] initWithNibName:@"FirstViewCtr" bundle:nil];
nextSecondViewCtr=[[SecondViewCtr alloc] initWithNibName:@"SecondViewCtr" bundle:nil];
nextThirdViewCtr=[[ThirdViewCtr alloc] initWithNibName:@"ThirdViewCtr" bundle:nil];
nextForthViewCtr=[[ForthViewCtr alloc] initWithNibName:@"ForthViewCtr" bundle:nil];
nextsixviewctr=[[sixviewctr alloc] initWithNibName:@"sixviewctr" bundle:nil];
}
else
{
nextFirstViewCtr = [[FirstViewCtr alloc] initWithNibName:@"FirstViewCtr-iPad" bundle:nil];
nextSecondViewCtr=[[SecondViewCtr alloc] initWithNibName:@"SecondViewCtr-iPad" bundle:nil];
nextThirdViewCtr=[[ThirdViewCtr alloc] initWithNibName:@"ThirdViewCtr-iPad" bundle:nil];
nextForthViewCtr=[[ForthViewCtr alloc] initWithNibName:@"ForthViewCtr-iPad" bundle:nil];
nextsixviewctr=[[sixviewctr alloc] initWithNibName:@"sixviewctr-iPad" bundle:nil];
}
[nextFirstViewCtr setTitle:@"1st tab"];
[nextSecondViewCtr setTitle:@"2nd tab"];
[nextThirdViewCtr setTitle:@"3rd tab"];
[nextForthViewCtr setTitle:@"4th tab"];
[nextsixviewctr setTitle:@"5th tab"];
nav1 = [[UINavigationController alloc] initWithRootViewController:nextFirstViewCtr];
nav2 = [[UINavigationController alloc] initWithRootViewController:nextSecondViewCtr];
nav3 = [[UINavigationController alloc] initWithRootViewController:nextThirdViewCtr];
nav4 = [[UINavigationController alloc] initWithRootViewController:nextForthViewCtr];
nav5 = [[UINavigationController alloc] initWithRootViewController:nextsixviewctr];
nav1.navigationBarHidden=YES;
nav2.navigationBarHidden=YES;
nav3.navigationBarHidden=YES;
nav4.navigationBarHidden=YES;
nav5.navigationBarHidden=YES;
MainTabBar = [[UITabBarController alloc] init];
MainTabBar.delegate = self;
[MainTabBar setViewControllers:[NSArray arrayWithObjects:nav1,nav2,nav3,nav4,nav5,nil]];
MainTabBar.view.frame=self.view.frame;
MainTabBar.selectedIndex=0;
[self.view addSubview:MainTabBar.view];
在登录视图控制器中,我调用了在app del中的connect方法,并且这可以正常工作,在调用connect方法时,对于正确的凭据,可以调用app del中用于身份验证的方法。
身份验证方法如下所示 TabBarAppDelegate 。
- (void)xmppStreamDidAuthenticate:(XMPPStream *)sender
{
DDLogVerbose(@"%@: %@", THIS_FILE, THIS_METHOD);
[self goOnline];
LoginPassViewController *obj_login = [[LoginPassViewController alloc] init];
[obj_login nextOne];
}
nexone方法如下所示,位于loginpassviewcnt中。它也被调用,但视图没有被推送。
此方法位于 LoginPassViewController ,并从 TabBarAppDelegate
调用 -(void)nextOne{
TabBarViewCtr *MainTab;
if(MainTab==nil){
MainTab=[[TabBarViewCtr alloc] initWithNibName:@"TabBarViewCtr" bundle:nil];
}
[self.navigationController pushViewController:MainTab animated:YES];
}
当从 LoginPassViewController 调用 nextOne 方法时,它会根据需要运行,但在从 TabBarAppDelegate 调用时则不行。 我没有收到任何错误,甚至申请也没有崩溃任何人都可以让我知道如何做到这一点。
提前致谢。