【问题标题】:Presenting ModalViewController Modally on iPad在 iPad 上模态显示 ModalViewController
【发布时间】:2012-06-07 03:13:42
【问题描述】:

我在 iPad 应用的 UISplitVC 中从 MasterViewController 调用此代码:

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

}

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

【问题讨论】:

    标签: ios ipad modal-dialog viewcontroller


    【解决方案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

    【讨论】:

    • 你好@Graver,我展示了modalView,它显示正常,现在我按下主页按钮并再次打开应用程序,发生的情况是在打开应用程序时,它关闭了我打开的modalView,如何防止这种情况
    • 你一定在某处做。在您调用的任何地方放置断点:dismissModalViewControllerAnimateddismissViewControllerAnimated 并调试以解决。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多