iOS - login view before uitabbarcontroller

2019-08-01 07:00发布

I want to display interface UITabBar when login succeeds. I declare interface UITabBar in AppDelegate, but after login success I don't know how to call the interface.

Here is my code:

appdelegate.m

    -(void)loadInterface
{
    [self configureiPhoneTabBar];
}

    -(void)configureiPhoneTabBar
    {
        UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
        UIViewController *controller1 = [[tabBarController viewControllers] objectAtIndex:0];
        [self configureTabBarItemWithImageName:@"home_ON.png" : @"home.png" andText:@"Trang chủ" forViewController:controller1];

        UIViewController *controller2 = [[tabBarController viewControllers] objectAtIndex:1];
        [self configureTabBarItemWithImageName:@"channel_ON.png" : @"tvChannel.png" andText:@"Kênh" forViewController:controller2];
    }

and loginviewcontroller.m

- (IBAction)btnLogin:(id)sender {
    [self performSegueWithIdentifier:@"idenLogin" sender:self];
    AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    [delegate loadInterface];
}

Secondly, when you touch on button "play", layout video shows and it works ok, but I want to auto rotate

note: This is interface on iphone and I fix Portrait in Summary, I'm still show landscape, How to do?

Can u download my code demo is here

2条回答
Evening l夕情丶
2楼-- · 2019-08-01 07:13

in couple of words you need modal view for login screen.

Here is how I did it (from app delegate class). Note that I have my login view designed in storytboard.

- (void) showLoginView
{
        assert(loginController == nil);
        assert(activityView == nil);

        UITabBarController *tabbar = (UITabBarController *)self.window.rootViewController;
        loginController = [tabbar.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
        loginController.delegate = self;
        [tabbar presentModalViewController:loginController animated:YES];
}
查看更多
看我几分像从前
3楼-- · 2019-08-01 07:25

I create an object in my AppDelegate called WindowState or similar that manages what should be the rootViewController of the window. Initially it would be a sign in or splash, then you can run checks in your WindowState class and listen for notifications eg. MyAppDidSignInNotification then change the rootViewController of your app to a UITabBarController or whatever there.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  self.windowState = [[FASWindowState alloc] initWithWindow:self.window];
  [self.window makeKeyAndVisible];

  return YES;
}
查看更多
登录 后发表回答