带登录屏幕的UITabbarControl [英] UITabbarControl with a login screen

查看:79
本文介绍了带登录屏幕的UITabbarControl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

any-body尝试了一个场景,比如第一次显示登录屏幕,在验证用户名后,应用程序以uitabbar控制器启动。

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.

我试过仅使用uitabbar的应用程序。将登录屏幕作为第一个视图放在tabbar控制器中,使用TabBarController.tabBar.hidden = TRUE;但视图变得扭曲(tabbar的空间仍然是空的)这里有一个可以帮助我正确显示视图?

i tried with the application with uitabbar only. with the login screen put as first-view in tabbar controller, with "TabBarController.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?

谢谢,
abhayadev s

thanks, abhayadev s

推荐答案

应用程序只需要使用LoginViewController,直到用户通过身份验证,注册,与FB或其他任何方式链接,然后应该释放LoginViewController,因为它不再需要。这个解决方案可能看起来有点矫枉过正,但我​​认为它延伸得很好。这是我的方式,在我的情况下,我只有一个Splash屏幕显示一些信息,然后用户进入应用程序的主要部分:

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:

首先我实际上我做了一个简单的协议,我可以在我的MainAppDelegate.m文件中实现,称为SplashDelegate:

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

然后我的MainAppDelegate实现了这一点。在应用程序启动后首先, self.window rootViewController 将指向我的SplashViewController,然后关闭之后, MainViewController (在OP的情况下,他的 TabViewController )将被实例化。

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.

这是我的主应用代表的重要部分 h 文件:

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;

m 文件的重要部分:

#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
 }  

然后在 SplashViewController (或 LoginViewController )中所需的只是你的登录测试和 parentDelegate 的属性。在 SplashViewController.h 里面我将 parentDelegate 设为一个实例变量,如 id< SplashDelegate> ; _parentDelegate 。另一个好主意是扩展上面的协议以减轻检查用户登录的责任,这样你就不会检查视图控制器类内部的登录。

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.

编辑:在 LoginViewController 内,你可以调用 [self.parentDelegate splashExit:self] ,并修改上面的想法以包括你的登录检查。

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

希望这对某人有帮助!

这篇关于带登录屏幕的UITabbarControl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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