阻止用户通过登录进入UITabBarController

时间:2013-04-25 13:07:44

标签: ios objective-c uitabbarcontroller

我有一个登录视图,该视图会导致UITabBarController有四个标签。 我想要的是当密码为空或错误时,提示用户保持在同一视图(登录视图)而不是标签栏控制器。换句话说,如果密码正常(非空且正确),我希望能够查看标签栏。是否可以继续显示登录视图,直到提供的密码正确为止?有什么想法吗?

3 个答案:

答案 0 :(得分:0)

据我所知,你想在一段时间内禁用你的标签栏。

如果您使用UITabBarController,则可以使用

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
    return NO; 
}

或者您可以停用userInteractionEnabled

myTabBar.userInteractionEnabled = NO;

您还可以为UITabBarController添加一些子视图,例如淡出标签栏

UIView *view = [[UIView alloc] initWithFrame:self.view.bounds];
view.backgroundColor = [UIColor blackColor];
view.alpha = 0.3f;
[self.tabBarController.view addSubview:view];
[view release];

答案 1 :(得分:0)

您所描述的是模态视图控制器。如果您有现有的登录控制器,请将其显示:

[someViewController presentViewController:loginController animated:YES completion:nil]

这会将loginController置于所有其他控制器上。当用户输入正确的密码(并且只有!)时,你应该忽略它:

[self dismissViewControllerAnimated:YES completion:nil];

如果您希望loginController有标题栏,请记得将其换成UINavigationController并改为显示导航控制器。

答案 2 :(得分:0)

YourAppDelegate.m:

@interface YourAppDelegate()
@property( nonatomic, retain ) UITabBarController *tabBarController;
@property( nonatomic, retain ) UIViewController *loginViewController;
- (void)allocateAndShowLoginViewController;
- (void)allocateAndShowMenuController;
@end
@implementation YourAppDelegate
@synthesize tabBarController;
@synthesize loginViewController;
#pragma mark -
#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];           
    [self.window makeKeyAndVisible];
    [self allocateAndShowLoginViewController];       
    return YES;
}

- (void)allocateAndShowLoginViewController{
     // Show Login View Controller (for example:)
     // My Sample login view controller uses delegate to report when user has been logged in
     self.loginViewController = [[[UIViewController alloc] initWithDelegate:self] autorelease];
     self.window.rootViewController = loginViewController;
}  

- (void)allocateAndShowTabBarController{
    self.tabBarController = [[[UITabBarController alloc] init] autorelease];

    UINavigationController      *viewController1 = [[[UINavigationController alloc] initWithRootViewController:[[[UIViewController alloc] init] autorelease]] autorelease];

    UINavigationController      *viewController2 = [[[UINavigationController alloc] initWithRootViewController:[[[UIViewController alloc] init] autorelease]] autorelease];

    self.tabBarController.viewControllers = @[viewController1, viewController2];
    self.tabBarController.customizableViewControllers = nil;

    self.window.rootViewController = self.tabBarController;
}


#pragma mark - loginViewControllerDelegate
- (void)loginViewControllerDidLogin:(PSLoginViewController*)controller{
    [self allocateAndShowMenuController];
}

像这样的东西

相关问题