UIAlertView在应用程序的最开始:didFinishLaunchingWithOptions:

时间:2013-11-17 05:17:27

标签: ios ios7 uialertview

我在申请一开始就有以下内容: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.
    ...
}

并且UIAlertView仍然显示出来。怎么运作?

1 个答案:

答案 0 :(得分:1)

警报视图显示在他们自己的窗口中。但是直到运行循环有机会运行才会发生这种情况。当您记录警报视图的超级视图时,警报尚未显示,这就是您获得(null)的原因。