如何在登录屏幕启动后显示标签栏控制器?
这是一个基于视图的应用程序。如何在登录屏幕启动后显示标签栏控制器?
在delegate.m文件我曾经做过这样的发动最初的登录界面:
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
[window addSubview:viewController.view];
[window makeKeyAndVisible];
LoginView *loginView=[[LoginView alloc]initWithNibName:@"LoginView" bundle:nil];
[window addSubview:loginView.view];
}
通过添加上面的代码我都推出了登录界面成功地,但在我的登录屏幕的底部,我可以看到留下一个空间。
如何能在标签栏控制器获得SUCESSFUL登录后推出?
我在LoginView.m文件creatd的方法称为登录:
-(void)login
{
if(login)
{
TabBarController *tabBarController = [[TabBarController alloc] initWithNibName:@"TabBarController" bundle:nil];
[self.view addSubView: aTabBarController.view];
}
[aTabBarController release];
请大家帮我出这个与相应的代码。
你必须建立在类似的appDelegate方法..并在appDelegate.h你必须创建这样
的UITabBarController * Obj_tabbar的对象;
,然后在.m文件,
-(void) switchToTabbarController
{
Obj_tabbar.delegate = self;
Obj_tabbar.selectedIndex = 0;
Tracking_HomeVC *obj = [[Tracking_HomeVC alloc]init];
[self tabBarController:Obj_tabbar didSelectViewController:obj];
[self.window addSubview:Obj_tabbar.view];
}
//此时Tracking_HomeVC是TabbarController的第一视图控制器。它会被添加到窗口。
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
if([tabBarController selectedIndex] == 0)
{
//Write your code here to do with the first view controller object.
}
}
,然后从你的LoginView这样称呼它..
-(void)LoginPressed
{
AppAppDelegate *delegate =(AppAppDelegate *) [[UIApplication sharedApplication] delegate];
[delegate switchToTabbarController];
}
您的登录视图(或它的控制器,如果你有一个,它看起来像你没有)应该告诉的appDelegate来交换RootViewController的是一个taBarController。你不希望loginview试图添加一个tabBar作为它自己的孩子。
做它在您的appdelegate创造一个像正常的一tabbarcontroller并将其设置为RootViewController的方法之一:
TOTabBarController *tabBarController = [[TOTabBarController alloc] init];
UIViewController *vc1 = [[UIViewController alloc] initWithNibName:nil bundle:nil];
UIViewController *vc2 = [[UIViewController alloc] initWithNibName:nil bundle:nil];
UIViewController *vc3 = [[UIViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController *vc2_nc = [[UINavigationController alloc] initWithRootViewController:vc2];
UINavigationController *vc3_nc = [[UINavigationController alloc] initWithRootViewController:vc3];
NSArray *viewControllers = [NSArray arrayWithObjects:vc1, vc2_nc, vc3_nc, nil];
[tabBarController setViewControllers:viewControllers];
//set tabbarcontroller as rootviewcontroller
[[self window] setRootViewController:tabBarController];
然后在登录屏幕显示模态(无动画),如果用户没有登录:
if (not logged in) {
UIViewController *lvc_nc = [[UIViewController alloc] init];
[[[self window] rootViewController] presentModalViewController:lvc_nc animated:NO];
}
希望帮助!
感谢您的回答球员我会尝试 – 2011-12-15 11:54:42
这个问题的可能的复制:http://*.com/ question/6034893/show-a-login-screen-a-tab-bar-controller – Niko 2011-12-15 10:40:05
你需要接受你之前提出的问题的答案如果你不能接受他们的答案,那么让人们努力回答你的问题是令人沮丧的。 – 2011-12-15 11:16:58