djTeller
djTeller

Reputation: 515

presentModalViewController Issue

I'm writing an iPhone application which you need to authenticate at the beginning. Therefore as soon as the application load in the viewDidLoad i allocate a UIViewController which is in-charge of registration and authentication and i present it like so:

- (void)viewDidLoad {
    [super viewDidLoad];
    self.registerProfile = [[[RegisterViewController alloc] initWithNibName:@"RegisterProfile" bundle:nil] autorelease];
    [self presentModalViewController:self.registerProfile animated:YES];
    [self.registerProfile release];
 }

For some reason it does not work when it is called from viewDidLoad. But if i create a button on that view and append the same code above, when i click it, it works and the view is presented.

Any idea why it does not work on viewDidLoad and with a button it does ?

I also tested an Apple example called NavBar. When a button is clicked it present a view using the presentModalViewController, when i added it to the ViewDidLoad it did not work!

What am i missing here ? I want that process to be automatically when the view loads and not by a push of a button.

Thanks!

Upvotes: 0

Views: 1165

Answers (2)

djTeller
djTeller

Reputation: 515

After playing around and searching the deep web I have found the solution. Put the same code inside viewDidAppear and not viewDidLoad since the view cannot be initialized yet.

Upvotes: 1

Enrico Susatyo
Enrico Susatyo

Reputation: 19790

I happen to have a code that's almost exactly the same as above and it works fine. Try to do this:

- (void)viewDidLoad {
    [super viewDidLoad];
    self.registerProfile = [[[RegisterViewController alloc] initWithNibName:@"RegisterProfile" bundle:nil] autorelease];
    registerProfile.delegate = self; //set delegate as yourself
    [self presentModalViewController:self.registerProfile animated:YES];
    //[self.registerProfile release]; //don't worry about releasing it, it's been autoreleased.
 }

Upvotes: 0

Related Questions