我正在开发一个应用程序,我需要向用户显示一个列表作为菜单(课程、课程、成绩、注销)。所以在此之前我需要显示一个登录屏幕。仅在成功且有效的登录后,我才需要将用户重定向到菜单。所以我计划开发一个基于 tabBar 的应用程序,有 4 个选项卡。在这里,我对如何在加载 TabBar 控制器之前添加登录视图控制器感到困惑。我希望每次都选择第一个选项卡。截至目前,我正在添加我的TabBar控制器作为我的 rootviewcontroller应用程序委托窗口然后将登录视图控制器呈现为模式视图控制器。但这里的问题甚至在登录视图控制器加载后,我的课程视图控制器已加载,因为 tabbarcontroller 首先加载。我的实际要求是我需要根据登录视图控制器中给出的输入加载课程视图控制器和课程列表。但是 loadview 当然视图控制器甚至在登录视图控制器的加载视图之前加载。所以无论谁登录,我的课程列表总是相同的。我在这里对如何前进感到困惑...这里的任何建议都会有很大帮助...
所以,一个非常简单的例子可以是:在你的loginViewController
你应该有一些像这样的方法:
//Call this after the user has done with the login
-(IBAction)remove:(id)sender{
AppDelegate *del=(AppDelegate*)[[UIApplication sharedApplication] delegate];
//Set some data based on the user's input (eg some property shared in the AppDelegate)
//del.dataEnterByTheUser=someData;
[del removeLoginView];
}
然后在你的AppDelegate
(假如说now the rootViewController
is the loginViewController
)你可以这样做(你可以优化转换):
-(void)removeLoginView{
UITabBarController *tabVC=[[UITabBarController alloc] init];
ViewController *v1=[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
//v1.data=self.dataEnterByTheUser;
ViewController *v2=[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
NSArray *arrayVC=[NSArray arrayWithObjects:v1,v2, nil];
[tabVC setViewControllers:arrayVC];
[tabVC setSelectedViewController:0];
CGRect rectVC=self.loginViewController.view.frame;
rectVC.origin.y=self.view.frame.size.height;
[UIView animateWithDuration:0.3f delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
self.loginViewController.view.frame=rectVC;
} completion:^(BOOL finished){
[self.loginViewController.view removeFromSuperview];
self.loginViewController=nil;
self.window.rootViewController=tabVC;
}];
}
还记得在每个 viewControllers 中设置initWithNibName:
the self.title
设置 tabItem 上的标题。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)