views:

116

answers:

3

Hello,

I'm trying to find a way that my program will show up a "setup"-view, when you first start the app, but it doens´t works.

Here is my attempt. The appdelegate should look, if the program opens the first time (abfrage = false) and open an other view.

#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];}
}
(...)

I tried to build a if-query in the appdelegate, but always when "abfrage" is false, the program just loads a white view.

A: 

Try this which is implemented in the "top level" view controller:

- (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];
}

Essentially I think you want to do this in viewDidAppear in your main view controller. At least that's how I did it.

Nimrod
I don´t know why, but my ViewController doens´t load the new view, if I set it in ViewDidAppear or viewDidLoad - I know, that my code is right, because when I but the essential code to a UIAction he load the new view with a push on a button.
Flocked
A: 

I got a solution, which can be set in the applicationDidFinishLaunching of the AppDelegate:

- (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];
    }
}
Flocked
A: 

The problem is that you initialize a new BenutzerdatenViewController, but don't add it to the window.

You need to add that after the initialization:

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