在iPad上模拟呈现ModalViewController

时间:2012-06-07 03:13:43

标签: ios ipad modal-dialog viewcontroller

我在UISplitVC中为一个iPad应用程序从MasterViewController调用此代码:

-(void)viewWillAppear:(BOOL)animated{
//PRESENT MODALVC
ModalViewController *modalVC = [[ModalViewController alloc] initWithNibName:@"ModalViewController" bundle:nil];
[self setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentModalViewController:modalVC animated:YES];

}

但它不起作用。没有出现ModalVC。

1 个答案:

答案 0 :(得分:1)

试试这段代码:

ModalViewController *modalVC = [[ModalViewController alloc] initWithNibName:@"ModalViewController" bundle:nil];
[modalVC setModalPresentationStyle:UIModalPresentationFullScreen]; //You set the presentation style of the controller that would be presented, not the presenting controller
//This check is needed, because presentModalViewController:animated is depreciated in iOS5.0 and presentViewController:animated:completion must be used instead. The same is valid for dismissModalViewControllerAnimated and dismissViewControllerAnimated:completion
if([self respondsToSelector:@selector(presentViewController:animated:completion:)])
    [self presentViewController:modalVC animated:YES completion:nil];
else
    [self presentModalViewController:modalVC animated:YES];

如果您定位的是iOS5.0 +,则不需要进行此项检查,您只能使用presentViewController:animated:completiondismissViewControllerAnimated:completion

相关问题