Pallavi
Pallavi

Reputation: 259

how to change property located in .plist called 'Main nib file base name' at run time

I have already added my MainWindow.xib file name in .plist file, if i want to change it at run time by another file name MainWindow2.xib. How do we change it by code?

Upvotes: 1

Views: 1946

Answers (1)

rckoenes
rckoenes

Reputation: 69499

You can't, since the info.plist is readonly on with the app bundle. You will have to do it by code.

Remove all mainwindows from the info.plist and here is an example:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    UIViewController *rootViewController = nil; 
    // Override point for customization after application launch.
    if (YES) { //You check here
        rootViewController = [[SomeViewController alloc] initWithNibName:@"SomeViewController" bundle:nil];
    } else {
        rootViewController = [[OtherViewContoller alloc] initWithNibName:@"OtherViewContoller" bundle:nil];
    }
    self.window.rootViewController = rootViewController;        
    [self.window makeKeyAndVisible];

    return YES;
}

The in the main.m:

#import <UIKit/UIKit.h>

#import "AppDelegate.h"

int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}

Upvotes: 1

Related Questions