Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

RottenApple2

macrumors newbie
Original poster
Nov 4, 2009
29
0
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!
 

jiminaus

macrumors 65816
Dec 16, 2010
1,449
1
Sydney
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;
}
 

RottenApple2

macrumors newbie
Original poster
Nov 4, 2009
29
0
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?
 

jiminaus

macrumors 65816
Dec 16, 2010
1,449
1
Sydney
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.
 

RottenApple2

macrumors newbie
Original poster
Nov 4, 2009
29
0
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.
 

jiminaus

macrumors 65816
Dec 16, 2010
1,449
1
Sydney
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?
 

jiminaus

macrumors 65816
Dec 16, 2010
1,449
1
Sydney
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.
 

RottenApple2

macrumors newbie
Original poster
Nov 4, 2009
29
0
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
?
 

RottenApple2

macrumors newbie
Original poster
Nov 4, 2009
29
0
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?
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.