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!

Answers


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.


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

Need Your Help

A simple way to convert to/from VARIANT types in C++

windows visual-c++ variant

Are there any easy-to-use, high-level classes or libraries that let you interact with VARIANTs in Visual C++?

Java execute .exe with user previlege

java windows permissions cmd

I've written a program in c# to change file and folder atributes in windows.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.