ios - 基于 iOS 应用程序设计 View Hierarchy Tabbar bar

标签 ios iphone objective-c ios7

开始新项目时仍然感到困惑。我有一个选项卡栏应用程序,其中包含许多选项卡以及与每个选项卡关联的导航 Controller 。

我需要在标签栏之前添加一个登录屏幕。还需要在用户登录一次时将用户带到标签栏。即,一旦用户登录,每次他被定向到标签栏,除非他注销。我需要选择一种模式。

  • 创建一个登录屏幕并模态显示标签栏 Controller ,并在用户注销时关闭模态视图 Controller 。
  • 当用户登录时将 window.rootViewController 更改为 tabbarcontroller,如果没有将 window.rootview Controller 设置为登录 View Controller 。
  • 在应用程序中确实完成了启动,[window addSubview:tabcontroller.view]
    然后 [window addSubview:loginviewcontroller.view] 并在用户成功登录时隐藏 loginviewcontroller
  • 与我的选项 1 正好相反,如果用户未登录并在登录时关闭,则显示标签栏 Controller 并模态显示登录 View Controller 。

  • 请选择我最好的选择或任何其他方式来做得更好。

    最佳答案

         **Changing the window.rootViewController to the tabbarcontroller
         when the user signs in and if not set the window.rootview controller 
         as the login view controller.** 
    

    是做这件事的最好方法,
    最初,如果用户未登录,则 LoginViewController 将是 RootViewController,否则 tabBarController 将是 RootViewController,并且当用户注销时,将 RootViewController 更改为 LoginViewController。

    更新:试试这个,这会奏效。如果不清楚,请告诉我,我将向您发送一个工作项目。

    Bydefault InitialViewController from your Main Storyboard is instantiated and displayed automatically when your app starts up. To prevent this happening you need to remove the UIMainStoryboardFile setting from your info.plist file.

    With no default view controller, you are now free to create one programmatically at app start.



    在这里,我在这一行下面写了一个小例子。创建两个没有 xib FirstViewController 和 SecondViewController 的 View Controller ,并在 MainStoryboard_iPhone 和 Appdelegate.m 中添加比实现这些方法。

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
    /*
     call any of the two methods below, it will change the RootViewController accordingly
     */
    
    // [self firstRootViewController];  // make FirstViewController Root view controller
    [self secondRootViewController];    // make SecondViewController Root view controller
    
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
    

    }

    - (void) firstRootViewController {
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
    FirstViewController *first = [sb instantiateViewControllerWithIdentifier:@"FirstViewController"];
    [self.window setRootViewController:first];
    

    }

    - (void) secondRootViewController {
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
    SecondViewController *second = [sb instantiateViewControllerWithIdentifier:@"SecondViewController"];
    [self.window setRootViewController:second];
    

    }

    现在在 MainStoryboard_iPhone.storyboard 中设置 viewController

    enter image description here

    关于ios - 基于 iOS 应用程序设计 View Hierarchy Tabbar bar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19566157/

    相关文章:

    iphone - iScroll 4 在 iOS 上的性能

    ios - 如何在swift中制作挥手进度条?

    iphone - iPhone 应用程序中的图像出现在模拟器中,但在编译到设备时不会出现

    ios - 从 iOS 上的 mov 文件中提取元数据

    iphone - 为什么要使用模态视图

    ios - 更改/动画 UITextView 中的最大行数?

    mysql - 当字符串包含空格时,应用程序仍未更新数据库

    iphone - Sencha Touch 2 如何在 Windows 上构建 iOS 应用程序?

    ios - 使用 max-age=0 自动过期 NSURLCache

    iphone - NSMutableDictionary SetObject :ForKey: is not inserting NSDictionary object