我有一个标签栏,其中包含五个标签。我的应用程序不需要用户登录。如果用户注册或登录,则只允许使用某些功能。
如果用户已经注册/登录,我在连接到 NavigationController
的 UserViewController
中实现了以下逻辑。但是,在以下逻辑中,用户仍然可以在一两秒内看到该 ViewController。
-(void) viewWillAppear: (BOOL) animated
{
if(isRegistered)
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UserProfileViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"UserProfileVewController"];
[self.navigationController pushViewController:vc animated:YES];
}
}
我想知道如果用户已经注册了,我怎么能跳过UserViewController呢?
我希望标签栏点击直接打开到 UserProfileVewController
而不是 UserViewController
这是登录/注册 View Controller 。
最佳答案
在项目的 AppDelegate 中,您可以检查用户是否登录/注册,并依赖地显示 ViewControllers:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
BOOL userIsLoggedIn = AMethodCheckIfUserLoggedIn();
if (userIsLoggedIn) {
UserProfileViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"UserProfileVewController"];
self.window.rootViewController = vc;
}
else{
UserViewController *userViewController = [storyboard instantiateViewControllerWithIdentifier:@"UserViewController"];
self.window.rootViewController = userViewController;
}
//... Other logic goes here
[self.window makeKeyAndVisible];
return YES;
}
关于ios - 在 NavigationController 中跳过登录 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41787549/