views:

25

answers:

1

Hey im trying to display a modal view controller as soon as my tab bar controller app opens.

There is something wrong with the code below, and im 99% sure its the code for this. what do i put for the thing im calling it on?

[self presentModalViewController:promt animated:YES];

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

// Override point for customization after app launch.


//Displays the password prompt modally 

PasswordPromViewController *promt = [[PasswordPromViewController alloc] initWithNibName:@"PasswordPromViewController" bundle:nil];
promt.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:promt animated:YES];
[promt release];






return YES;
}

any ideas would be helful! Cheers

+1  A: 

I'm guessing you're adding this code in the application delegate file (eg if your app is called XXX then XXXAppDelegate.m). If this is the case you cannot use:

[self presentModalViewController:promt animated:YES];

as this method has to be called on an instance of a UIViewController. If you've set up your project in the standard way then your app delegate should have an object called window, which is a reference to the main window of the application. It's probably simplest if you add the modal view controller to that, like so:

[window presentModalViewController:promt animated:YES];
pheelicks