platypus
platypus

Reputation: 1205

UIAlertView at the very beginning of application:didFinishLaunchingWithOptions:

I have the following at the very beginning of application:didFinishLaunchingWithOptions:

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

    UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"Reminder:" message:@"foo" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alertView show];
    NSLog(@"%@ is the parent view",[alertView superview]); // prints "(null)"

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    ...
}

and the UIAlertView still showed up. How come this works?

Upvotes: 0

Views: 182

Answers (1)

rmaddy
rmaddy

Reputation: 318924

Alert views are shown in their own window. But this doesn't happen until the run loop is given a chance to run. At the time you log the alert view's superview, the alert hasn't been shown yet which is why you get (null).

Upvotes: 1

Related Questions