Ipad presentModalViewController在ViewController上

时间:2011-11-30 13:21:36

标签: iphone objective-c ios ipad

我有ViewController(Passwordviewcontroller),我想用“presentModalviewController”显示

我有一个AppDeleage:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

这是我希望PasswordviewController显示的My ViewController:

-ViewDidLoad
{
    self.passwordView = [[PasswordView alloc]initWithNibName:@"PasswordView" bundle:nil];
    [passwordView setModalPresentationStyle:UIModalPresentationFullScreen];
    [self presentModalViewController:passwordView animated:YES];
}

我尝试了一切,但仍然无法正常工作,有人有想法吗?

1 个答案:

答案 0 :(得分:0)

将其放在viewDidAppear而非viewDidLoad中。在viewDidLoad中,您的视图可能会加载到内存中,但不一定要在屏幕上显示。另一方面,在viewDidAppear中,您的视图已准备好显示在窗口中正确插入,以便您可以显示模态视图。

修改:根据评论

viewWillAppear更改为viewDidAppear