2

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,...

RJFalconer
  • 10,890
  • 5
  • 51
  • 66
Ploetzeneder
  • 1,281
  • 4
  • 20
  • 34

2 Answers2

1

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.

Arlen Anderson
  • 2,486
  • 2
  • 25
  • 36
0

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.

lucius
  • 8,665
  • 3
  • 34
  • 41