ios - 在 NavigationController 中跳过登录 View Controller

标签 ios objective-c

我有一个标签栏,其中包含五个标签。我的应用程序不需要用户登录。如果用户注册或登录,则只允许使用某些功能。

如果用户已经注册/登录,我在连接到 NavigationControllerUserViewController 中实现了以下逻辑。但是,在以下逻辑中,用户仍然可以在一两秒内看到该 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 。

enter image description here

最佳答案

在项目的 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/

相关文章:

ios - 如何让 MapKit 标注按钮执行 segue?

ios - 在我的 XCode 项目中找不到 Cordova.plist

iphone - 在uitableview上添加整理分隔符

objective-c - 如何处理openGL中几个圆圈的淡出?

ios - 在 objective-c 中刷新 Gmail API 访问 token 的正确方法

ios - 为什么我以编程方式添加的 UIView 没有连接到我的 UIViewController?

ios - 我想从 NSData 加载图像但滚动不流畅

ios - 将数据附加到帖子正文并上传到 api

objective-c - 如何在 tableView :viewForFooterInSection 中添加 UIButton 或 UISwitch

iphone - 为创建的 UIToolbar 设置 UIToolbarPosition