我正在使用一个项目,我必须有一个登录页面,成功登录后,当我尝试使用以下代码加载标签栏控制器时,我们应该有一个标签栏视图(我正在使用标签栏控制器)。什么都没有用。
LoginSuccess *viewController = [[LoginSuccess alloc] initWithNibName:@"LoginSuccess" bundle:nil];
[self.view addSubview:viewController.tabBarController.view];
[viewController release];
请帮帮我。
答案 0 :(得分:1)
我做同样的工作,但是在登录响应成功后我调用了appdelegate
[mAppDelegate loadTabbar];
//在委托文件中调用函数以加载标签栏视图,跟随哪些代码
#pragma mark -
#pragma mark Load TabBar
-(void)loadTabBar
{
self.tabBarController = [[UITabBarController alloc] init];
tabBarController.delegate = self;
MyAlarmVC *myAlarmVC = [[MyAlarmVC alloc] initWithNibName:@"MyAlarmVC" bundle:nil];
UINavigationController *myAlarmNVC = [[UINavigationController alloc] initWithRootViewController:myAlarmVC];
myAlarmNVC.navigationBar.tintColor = [UIColor whiteColor];
[myAlarmVC release];
MyVideosVC *myVideoVC = [[MyVideosVC alloc] initWithNibName:@"MyVideosVC" bundle:nil];
UINavigationController *myVideoNVC = [[UINavigationController alloc] initWithRootViewController:myVideoVC];
myVideoNVC.navigationBar.tintColor = [UIColor whiteColor];
[myVideoVC release];
MyFriendsVC *myFriendVC = [[MyFriendsVC alloc] initWithNibName:@"MyFriendsVC" bundle:nil];
UINavigationController *myFriendNVC = [[UINavigationController alloc] initWithRootViewController:myFriendVC];
myFriendNVC.navigationBar.tintColor = [UIColor whiteColor];
[myFriendVC release];
MyMessageVC *myMessageVC = [[MyMessageVC alloc] initWithNibName:@"MyMessageVC" bundle:nil];
UINavigationController *myMessageNVC = [[UINavigationController alloc] initWithRootViewController:myMessageVC];
myMessageNVC.navigationBar.tintColor = [UIColor whiteColor];
[myMessageVC release];
MyProfileVC *myProfileVC = [[MyProfileVC alloc] initWithNibName:@"MyProfileVC" bundle:nil];
UINavigationController *myProfileNVC = [[UINavigationController alloc] initWithRootViewController:myProfileVC];
myProfileNVC.navigationBar.tintColor = [UIColor whiteColor];
[myProfileVC release];
tabBarController.viewControllers = [NSArray arrayWithObjects:myAlarmNVC,myVideoNVC, myFriendNVC,myMessageNVC,myProfileNVC, nil];
[myAlarmNVC release];
[myVideoNVC release];
[myProfileNVC release];
[myFriendNVC release];
[myMessageNVC release];
[self.window addSubview:tabBarController.view ];
//tabBarController.navigationController.navigationBarHidden = YES;
[self.tabBarController release];
}
- (void)tabBarController:(UITabBarController *)tabBarController1 didSelectViewController:(UIViewController *)viewController{
NSArray *vc= tabBarController1.viewControllers;
for (int i = 0; i < [vc count]; i++) {
UINavigationController *nc = [vc objectAtIndex:i];
if (nc == tabBarController1.selectedViewController) {
continue;
}
[nc popToRootViewControllerAnimated:NO];
}
}
如果您遇到问题,请告诉我您的标签栏的视图名称