Hiding a TabView programmatically

Discussion in 'iOS Programming' started by RottenApple2, Oct 8, 2011.

  1. RottenApple2 macrumors newbie

    Joined:
    Nov 4, 2009
    #1
    Hi, I have a TabView which controls multiple Views and I would like to hide one of them from the release build, but still keeping it in the project as I need it for testing purposes. How can I do this programmatically? It should not be visible to the user at all. Thanks!
     
  2. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #2
    You could use conditional compilation for this.

    For example, to change the default Tabbed Application project so that the second view controller only appears in debug builds, you could change application:didFinishLaunchingWithOptions: to:
    Code:
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
        // Override point for customization after application launch.
        self.tabBarController = [[[UITabBarController alloc] init] autorelease];
        UIViewController *viewController1 = [[[MYFirstViewController alloc] initWithNibName:@"MYFirstViewController" bundle:nil] autorelease];
    [COLOR=red]#if defined(DEBUG)[/COLOR]
        UIViewController *viewController2 = [[[MYSecondViewController alloc] initWithNibName:@"MYSecondViewController" bundle:nil] autorelease];
        self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];
    [COLOR=red]#else[/COLOR]
        self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, nil];
    [COLOR=red]#endif[/COLOR]
        self.window.rootViewController = self.tabBarController;
        [self.window makeKeyAndVisible];
        return YES;
    }
    
     
  3. RottenApple2 thread starter macrumors newbie

    Joined:
    Nov 4, 2009
    #3
    Hiding TabView in the release build...

    Thank you for the prompt and excellent reply!
    Do you know if there is an alternative option which would allow to compile it in release mode but still keeping one of the TabViews hidden?
     
  4. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #4
    I don't understand. What I posted does that. In a debug build, both the first and second view controllers will appear in the tab bar. In a release build, only the first view controller will appear, the second view controller is hidden.
     
  5. RottenApple2 thread starter macrumors newbie

    Joined:
    Nov 4, 2009
    #5
    Because I would like to build one version with all the views (for myself) and another one with one view disabled (for the general public). Both would need to be built on the device and in release mode.
     
  6. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #6
    Do you want two different builds (both in release build) in which one has the tab and the other doesn't have the tab? Or do you want a single build in which you perform some secret that reveals the testing view?
     
  7. RottenApple2 thread starter macrumors newbie

    Joined:
    Nov 4, 2009
    #7
    Well, the second one would be the PERFECT option!
     
  8. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #8
    For the first option, you could change the #if defined(DEBUG) to #if 1 when you want the build to include the extra view and change it to #if 0 when you want the build to exclude the extra view.

    For the second option, you'd need to implement the secret. For example, you could use a gesture recogniser to look for a particular gesture, or perhaps you could react when you enter a particular string into a text field. But if I seem to recall so-called easter eggs are against the App Store rules.
     
  9. RottenApple2 thread starter macrumors newbie

    Joined:
    Nov 4, 2009
    #9
    Great stuff!!! Thank you so much for your help. When I have a minute I will try and let you know if I have any problem.

    I have a doubt on the syntax. Is it just a plain and simple
    Code:
    #if 1 
    ?
     
  10. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #10
    Yes, just plain and simple #if 1. http://gcc.gnu.org/onlinedocs/cpp/If.html
     
  11. RottenApple2 thread starter macrumors newbie

    Joined:
    Nov 4, 2009
  12. RottenApple2, Oct 9, 2011
    Last edited: Oct 10, 2011

    RottenApple2 thread starter macrumors newbie

    Joined:
    Nov 4, 2009
    #12
    Hi, I am finding it more difficult than expected as I have created the TabBarController and all its ViewControllers via interface builder rather than programmatically and the ViewControllers appear as "undeclared" when I call them from the TabBarDelegate...

    Do you know how I can name them and reference to them?
     

Share This Page