iPhone Loading Different Views
I have to xibs, and I want to load which one the user wants in the settings. I'm just working on actually loading them and how would this been done.
This is the function in the delegate which I think would be where this happens.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
return YES;
}
This is the delegate header file.
#import <UIKit/UIKit.h>
@class myAppViewController;
@interface myAppAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
myAppViewController *viewController;
}
@property (nonatomic, ret开发者_如何学JAVAain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet myAppViewController *viewController;
@end
So lets say I have a xib created called modernTheme, how would I load that or the myAppViewController. If someone could do this in a generic if statement, that would be great.
This looks like your viewController
is being created 'in Interface Builder'. Instead of that you could create the ViewControllers yourself and add them dynamically. Your application:didFinishLaunchingWithOptions:
could look something like this:
UIViewController *viewController;
if (showModernTheme) { // from your configuration
viewController = [[YourViewControllerA alloc] initWith…];
} else {
viewController = [[YourViewControllerB alloc] initWith…];
}
// assuming YourViewControllerA + B are inheriting from UIViewController
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
Hope that helps
–f
精彩评论