2010-01-04 32 views
2

我試圖找到一種方法,當我第一次啓動應用程序時,我的程序將顯示一個「設置」 - 視圖,但它不起作用。如何獲得「第一次打開」 - 查看我的應用程序?

這是我的嘗試。如果程序第一次打開(abfrage = false)並打開另一個視圖,appdelegate應該看起來。

#import "TweetButtonAppDelegate.h" 
#import "TweetButtonViewController.h" 
#import "BenutzerdatenViewController.h" 

@implementation TweetButtonAppDelegate 

@synthesize window; 
@synthesize viewController; 
@synthesize abfrage; 


- (void)applicationDidFinishLaunching:(UIApplication *)application { 
    abfrage = FALSE; 
if (abfrage == TRUE) { 
    [window addSubview:viewController.view]; 
    [window makeKeyAndVisible]; 
} else { 
    BenutzerdatenViewController *Benutzerdaten = [[BenutzerdatenViewController alloc] initWithNibName:nil bundle:nil]; 
    [Benutzerdaten release];} 
} 
(...) 

我試圖建立在一個的appdelegate如果查詢,但總是當「abfrage」是假的,程序公正加載白的觀點。

回答

0

我得到了一個解決方案,它可以在AppDelegate中的在applicationDidFinishLaunching設置:

- (void)applicationDidFinishLaunching:(UIApplication *)application { 
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
    NSString *firsttime = [defaults stringForKey:@"firsttime"]; 
    if (firsttime == nil) { 

     TheOtherViewController *Other = [[TheOtherViewController alloc] initWithNibName:nil bundle:nil]; 
     Other.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
     [window addSubview: Other.view];   

     [defaults setObject:@"lasttime" forKey:@"firsttime"]; 
    } else { [window addSubview:viewController.view]; 
     [window makeKeyAndVisible]; 
    } 
} 
0

試試這個這是在「頂級」視圖控制器實現的:

- (void)viewDidAppear:(BOOL)animated { 
    [flasher setSettingsFromModel:self.settingsModel]; 
    if (self.settingsModel.warningAccepted == NO) { 
     [self showWarning]; 
     [flasher setFlashingEnabled:NO]; 
    } else 
     [flasher setFlashingEnabled:YES]; 
    [super viewDidAppear:animated]; 
} 

... 

- (void)modalViewControllerDidFinish:(UIViewController *)controller { 
     if (self.settingsModel.warningAccepted == YES) 
      [flasher setFlashingEnabled:YES]; 
     [self dismissModalViewControllerAnimated:YES]; 
} 

... 

- (void)showWarning { 
     WarningViewController *controller = [[WarningViewController alloc] 
         initWithNibName:@"WarningView" bundle:nil]; 
     controller.delegate = self; 
     controller.settingsModel = settingsModel; 
      controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical; 
     [self presentModalViewController:controller animated:YES]; 
     [controller release]; 
} 

基本上我想你想在你的主視圖控制器爲此在viewDidAppear。至少我是這麼做的。

+0

我不知道爲什麼,但我的ViewController好好嘗試加載新的看法,如果我在ViewDidAppear或viewDidLoad中設置它 - 我知道,我的代碼是正確的,因爲當我只是UIAction的基本代碼時,他通過按下按鈕加載新視圖。 – Flocked 2010-01-04 02:11:59

0

的問題是,你初始化一個新BenutzerdatenViewController,但不要把它添加到窗口。

你需要補充的是,初始化後:

[window addSubview: Benutzerdaten.view]; 
[window makeKeyAndVisible]; 
相關問題