重定向到 RootViewController ios
Redirect to RootViewController ios
我正在修改具有主屏幕设置的旧 ios 应用程序:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
rootViewController = [UITabBarController new];
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
[self setup];
如何以编程方式重定向回该屏幕?我正在添加一个登录屏幕,需要知道如何在成功登录后重定向。
谢谢
#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];
我正在修改具有主屏幕设置的旧 ios 应用程序:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
rootViewController = [UITabBarController new];
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
[self setup];
如何以编程方式重定向回该屏幕?我正在添加一个登录屏幕,需要知道如何在成功登录后重定向。
谢谢
#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];