Question

why does this not work:

- (void)viewDidLoad {
Login *neu =[[Login alloc] initWithNibName:nil bundle:nil];
    [self presentModalViewController:neu animated:NO];
}

but this works

-(IBAction)dologin:(id)sender{
Login *neu =[[Login alloc] initWithNibName:nil bundle:nil];
    [self presentModalViewController:neu animated:NO];
}

I wanted to load a specified class directly when one is loaded,...

Was it helpful?

Solution

I think it will work if you move [self presentModalViewController:neu animated:NO]; to viewDidAppear:

That way the modal view controller will pop up as soon as the view appears.

OTHER TIPS

viewDidLoad: isn't where you want to put up a modal view. It might be called after a low memory warning unloads your view controller, and then when the user navigates back to it, it will unexpectedly try to show a modal view. If you want to present something when the app launches, do so in applicationDidFinishLaunching: in your app delegate, or set up a NSNotfication observer:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidFinishLaunching:) name:UIApplicationDidFinishLaunchingNotification object:nil];

and call presentModalViewController: there.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top