Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

presentModalViewController in viewDidLoad on first launch

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

like image 353
Giles Van Gruisen Avatar asked Jan 04 '10 05:01

Giles Van Gruisen


3 Answers

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];
        }
    }
}
like image 73
rob5408 Avatar answered Sep 27 '22 20:09

rob5408


[UPDATE]

Fixed simply by using..

-(void)viewDidAppear:(BOOL)animated 
{

}

instead of

-(void)viewDidLoad
{

}

Thanks anyway!

/idiocy

like image 23
Giles Van Gruisen Avatar answered Sep 27 '22 21:09

Giles Van Gruisen


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

like image 44
Marian André Avatar answered Sep 27 '22 20:09

Marian André