【问题标题】:Redirect to RootViewController ios重定向到 RootViewController ios
【发布时间】:2019-08-11 15:29:59
【问题描述】:

我正在修改具有主屏幕设置的旧 ios 应用程序:

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
rootViewController = [UITabBarController new];
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
[self setup];

如何以编程方式重定向回该屏幕?我添加了一个登录屏幕,需要知道成功登录后如何重定向。

谢谢

【问题讨论】:

    标签: ios vlc


    【解决方案1】:
    #define kUserAuthChangedNotification  @"kUserAuthStatusChanged"
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        [self changeRootControllerWithIsUserSignIn:NO];//You must send user sign in or not
        [self.window makeKeyAndVisible];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(userAuthStatusChanged) name:kUserAuthChangedNotification object:nil];
    }
    
    #pragma mark helper methods
    
    - (void)userAuthStatusChanged {
        [self changeRootControllerWithIsUserSignIn:YES];//You must send user sign in or not
    }
    
    - (void)changeRootControllerWithIsUserSignIn:(BOOL)isSignIn {
        if(isSignIn){ 
            rootViewController = [UITabBarController new];
            self.window.rootViewController = rootViewController;
            [self setup];
        } else {
            YourLoginViewController * ctrl = [YourLoginViewController new];
            self.window.rootViewController = ctrl;
        }
    }
    

    当成功登录或注销时必须调用:

    [[NSNotificationCenter defaultCenter] postNotificationName:kUserAuthChangedNotification object:nil];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-04-08
      • 2020-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-26
      • 1970-01-01
      相关资源
      最近更新 更多