views:

695

answers:

4

I've been searching around but unfortunately have had no luck.

My app requires the user to sign in/sign up the first time he or she launches the app. I know how to determine first launch (using NSUserDefaults) but whenever I try to present the modal containing the sign in/ sign up controls, nothing happens.

Here's what I have:

-(void)viewDidLoad {
    [self showLogin];
    [super viewDidLoad];
}

-(void)showLogin {    
    FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:@"AccountView" bundle:nil];
    controller.delegate = self;

    controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    [self presentModalViewController:controller animated:YES];

    [controller release];
}

However, nothing happens. The main view just loads as normal. Any help is greatly appreciated.

-Giles

A: 

[UPDATE]

Fixed simply by using -(void)viewDidAppear:(BOOL)animated {} instead of -(void)viewDidLoad {}. Thanks anyway!

/idiocy

Giles Van Gruisen
+1  A: 

I had the same issue and ended up using viewDidAppear as well. The only problem with the viewDidAppear approach is that if you load other UIViewControllers on top, then reshow the base, then your setup code gets called over and over. I ended up having to add a boolean value (initialised to YES) to this view controller and check that value before deciding what to do. Hope this helps someone...

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:(BOOL)animated];

    if(justLaunched)
    {
        justLaunched = NO;
        if(settingsFileExists)
        {
            [self displayMainView];
        }
        else
        {
            [self displaySetupView];
        }
    }
}
rob5408
A: 

And invoking this in the viewDidLoad isn't very safe : the sequence viewDidLoad / viewDidUnload can occur at runtime when the iPhone needs to release some views in order to get back some free memory.

The side effect of such sequence would be that your login controller would be shown...

As you said the viewDidAppear looks better but not simply put it at the end of the appDidFinishedLaunching the delegate of your UIApplication?

yonel
A: 

How about using performSelector:withObject:afterDelay in the viewDidLoad function? That's how I do it, with a short delay of 0.1s.

Marian André