开发者

UITabbarControl with a login screen

any-body tried a scenario like, a login screen to show for the first time and after validation of username the application starts with uitabbar controller.

i tried with the application with uitabbar only. with the login screen put as first-view in tabbar controller, with "Tab开发者_JS百科BarController.tabBar.hidden=TRUE;" but the view is getting distorted (the space for tabbar is still empty) and here some one can help me in getting the view properly displayed?

thanks, abhayadev s


another possibility is to show the login viewController as a modal viewController. Modal VC hide the tabbar.


Create another viewController (e.g. LoginViewController). In your AppDelegate in applicationDidFinishLaunching: add (isLogged is just for exemple):

if (self.isLogged) {
   [window addSubview:self.tabBarViewController.view];
} else {
   LoginViewController *loginVC = [[LoginViewController alloc] initWithNibName:@"login" bundle:nil];
   [window addSubview:loginVC.view];
}

And you should call a method when login is successful that removes loginVC view and add tabBarController.view on the window.

It's no more complicated than that.


The application only needs to use the LoginViewController until the user is authenticated, signed up, linked with FB or whatever, and then that LoginViewController should be released as it is no longer needed. This solution might look like overkill but I think it extends well. Here's how I do it, and in my case I just had a Splash screen that displayed some information and then the user goes to the main part of the application:

First I actually made a simple protocol which I can implement in my MainAppDelegate.m file, called SplashDelegate:

//SplashDelegate.h

@protocol SplashDelegate <NSObject>
 - (void) splashExit : (id) sender;
@end

Then my MainAppDelegate implements that. First after the application launches, self.window's rootViewController will point to my SplashViewController, then after that is closed, the MainViewController (in OP's case his TabViewController) will be instantiated.

Here's the important part of my main app delegate h file:

#import "SplashDelegate.h"

@class MainViewController;
@class SplashViewController;

@interface MainWithLoginPageAppDelegate : NSObject <UIApplicationDelegate, SplashDelegate> {
    MainViewController *_viewController;
    UIWindow *_window;
    SplashViewController *_splashViewController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet MainViewController *viewController;
@property (nonatomic, retain) IBOutlet SplashViewController *splashViewController;

And the important part of the m file:

#import "MainWithLoginPageAppDelegate.h"
#import "MainViewController.h"
#import "SplashViewController.h"

@implementation MainWithLoginPageAppDelegate
@synthesize window=_window;
@synthesize viewController=_viewController;
@synthesize splashViewController = _splashViewController;

- (void) splashExit : (id) sender
{
    _viewController = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];
    self.window.rootViewController = self.viewController;
    [_splashViewController release];

}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    //initialize my splash controller
    _splashViewController = [[SplashViewController alloc] initWithNibName:@"SplashViewController" bundle:nil];

    self.splashViewController.parentDelegate = self;

    self.window.rootViewController = self.splashViewController;

    [self.window makeKeyAndVisible];
    return YES;
    //note that _viewController is still not set up... it will be setup once the login phase is done
 }  

Then all you need in the SplashViewController (or LoginViewController) is your login test and your property for the parentDelegate. Inside of SplashViewController.h I make my parentDelegate an instance variable, as id <SplashDelegate> _parentDelegate. Another good idea would be to extend the protocol above to offload the responsibility of checking the user's login so that you're not checking the login inside of the view controller class.

Edit: Inside of the LoginViewController, then, you can call [self.parentDelegate splashExit:self], and modify the idea above to include your login checks as well.

Hope this is helpful to someone!


Have the login page in the firstview controller.Add the tabbar to the window only after navigating to the second view controller.Thats it.

All the best.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜