回答

3

假設你有那是你的同步過程中設置,在初始視圖控制器initWithNibNamed您的應用程序委託一個屬性:方法檢查由應用程序代理同步的值,並加載適當筆尖通過調用[super initWithNibNamed:@"thisNibInsteadOfThatNib"];

編輯:顯示代碼以啓動取決於一些條件,在發射

// AppDelegate.h 
#import <UIKit/UIKit.h> 

@interface AppDelegate : NSObject <UIApplicationDelegate> 
{ 
    UIWindow *window; 
    UIViewController *firstViewController; 
} 
@property {nonatomic, retain} UIWindow *window; 
@end 

// AppDelegate.m 
#import AppDelegate.h 
#import ViewControllerOne.h 
#import ViewControllerTwo.h 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    BOOL shouldLoadViewOne = \\ some value from preferences 

    if (shouldLoadViewOne) { 
     firstViewController = [[ViewOneController alloc] initWithNibName:@"ViewOneController" bundle:nil]; 
    } else { 
     firstViewController = [[ViewTwoController alloc] initWithNibName:@"ViewTwoController" bundle:nil]; 
    } 

    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:firstViewController]; 

    [window addSubView:[navController view]]; 

    [window makeKeyAndVisible]; 

    return YES; 
} 

EDIT 2的不同視圖:

使用NSClassFromSting()並保存要在首選項中加載的firstViewController的名稱。

// AppDelegate.h 
#import <UIKit/UIKit.h> 

@interface AppDelegate : NSObject <UIApplicationDelegate> 
{ 
    UIWindow *window; 
    id firstViewController; 
} 
@property {nonatomic, retain} UIWindow *window; 

- (NSString *)firstViewControllerName; 

@end 

// AppDelegate.m 
#import AppDelegate.h 
#import ViewControllerOne.h 
#import ViewControllerTwo.h 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    NSString *viewControllerName = [self firstViewControllerName]; 

    firstViewController = [[NSClassFromString(viewControllerName) alloc] initWithNibName:viewControllerName bundle:nil]; 

    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:firstViewController]; 

    [window addSubView:[navController view]]; 

    [window makeKeyAndVisible]; 

    return YES; 
} 

- (NSString *)firstViewControllerName 
{ 
    NSString *defaultViewController = @"ViewOneController"; 
    NSString *savedFirstViewController = // string retrieved from preferences or other persistent store 

    if (!savedFirstViewController) 
     return defaultViewController; 

    return savedFirstViewController; 
} 
+1

可替代地,如果有用於每個筆尖不同視圖控制器(ViewOneController,ViewTwoController)初始化,你需要基於從同步在'的applicationDidFinishLaunching條件加載控制器或視圖:當然此的 – falconcreek 2010-06-04 13:20:26

+0

'假設這不是一個「國際化」問題,如果您按照Apple文檔創建必要的nib文件,在運行時會自動處理這個問題 – falconcreek 2010-06-04 13:24:08

+0

您可以詳細說明初始化'didFinishLaunchingWithOptions:'嗎? – Brandon 2010-06-04 14:24:06

相關問題