如何获得“第一次打开” - 查看我的应用程序?

时间:2010-01-04 01:36:59

标签: iphone objective-c xcode

我正试图找到一种方法,当你第一次启动应用程序时,我的程序会显示“设置” - 视图,但它确实无效。

这是我的尝试。如果程序第一次打开(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中构建一个if-query,但是当“abfrage”为false时,程序只会加载一个白色视图。

3 个答案:

答案 0 :(得分: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中这样做。至少我是这样做的。

答案 1 :(得分: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];
    }
}

答案 2 :(得分:0)

问题是你初始化一个新的BenutzerdatenViewController,但是不要把它添加到窗口。

您需要在初始化后添加:

[window addSubview: Benutzerdaten.view];
[window makeKeyAndVisible];