如何开发具有登录功能的基于TabBar的应用程序? [英] How to develop a TabBar based application with a login functionality?

查看:73
本文介绍了如何开发具有登录功能的基于TabBar的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,其中我需要向用户显示一个列表作为菜单(课程,课程,成绩,注销).因此,即使在此之前,我也需要显示登录屏幕.仅在成功且有效的登录后,我才需要将用户重定向到菜单.所以我计划开发一个带有4个选项卡的基于tabBar的应用程序.在这里,即使在TabBar控制器加载之前,我仍然对如何添加登录视图控制器感到困惑.我希望每次都选择第一个标签.到目前为止,我正在将 TabBar控制器作为rootviewcontroller添加到我的 AppDelegate窗口,然后将登录视图控制器呈现为模式视图控制器.但是这里的问题甚至在加载 Login View控制器之前,我的课程视图控制器也已加载,因为首先加载了tabbarcontroller.我的实际要求是,我需要根据登录视图控制器中提供的输入向课程视图控制器加载课程列表.但是,即使在登录视图控制器的加载视图之前,也加载了课程视图控制器的loadview.所以无论谁登录,我的课程清单总是一样的.我对如何前进感到困惑...这里的任何建议都会有很大帮助...

I am developing an application where i need to show a list as a menu(Courses,lessons,grade,logout) to the user. so even before this i need to show a login screen. Only upon successful and valid login i need to re-direct the user to the menu. So i have planned to develop a tabBar based application with 4 tabs. Here i am confused on how to add the login view controller even before the TabBar controller is loaded. I want the first tab to be selected every time. As of now i am adding my TabBar controller as a rootviewcontroller to my AppDelegate window and then presenting the login view controller as a modal view controller. But the problem here is even before the Login View controller is loaded, my courses view controller is loaded because the tabbarcontroller is loaded first. My actual requirement is i need to load the course view controller with the list of courses based on the inputs given in the Login View controller. But loadview of course view controller is loaded even before the load view of login view controller. so my list of courses is always the same irrespective of who logs in. I am confused here on how to move forward...Any suggestion here would be of great help...

推荐答案

因此,一个非常简单的例子可能是:在您的loginViewController中,您应该具有类似以下的方法:

So, a very quick example, could be; in your loginViewController you should have some method something like this:

//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(假设现在 rootViewControllerloginViewController)中执行以下操作(可以优化转换):

Then in your AppDelegate (assuming that now the rootViewController is the loginViewController) you could do like this (you can optimize the transition):

-(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:中设置self.title以在tabItem上设置标题.

Also remember to set in each viewControllers's initWithNibName: the self.title to set the title on the tabItem.

这篇关于如何开发具有登录功能的基于TabBar的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆