UISplitViewControllers中的presentModalViewController detailView不会全屏显示视图

时间:2012-04-24 12:10:32

标签: objective-c ios ipad

我在mainViewControllers视图中添加了UISplitViewController视图,代码如下。

    documentsRootViewController = [[DocumentsRootViewController alloc] initWithStyle:UITableViewStylePlain];
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:documentsRootViewController];
    documentsRootViewController.title = @"Document List";

    documentDetailView = [[DocumentsDetailView alloc] initWithNibName:@"DocumentsDetailView" bundle:nil];
    documentsRootViewController.detailViewController = documentDetailView;

    docSplitViewController = [[UISplitViewController alloc] init];
    docSplitViewController.viewControllers = [NSArray arrayWithObjects:navigationController, documentDetailView, nil];
    docSplitViewController.delegate = documentDetailView;

    CGRect splitViewFrame = CGRectMake(0, 0, cetralArea.frame.size.width, cetralArea.frame.size.height);         
    docSplitViewController.view.frame = splitViewFrame;
    [cetralArea addSubview:docSplitViewController.view];

现在我想要的是从UISplitViewController的DetailView呈现一个ViewController我试图在DetailViewControllers下面单击我这样做!按钮点击。

enter image description here

- (IBAction) buttonClicked:(id)sender
{
    NSString *phrase = nil; // Document password (for unlocking most encrypted PDF files)    
    NSArray *pdfs = [[NSBundle mainBundle] pathsForResourcesOfType:@"pdf" inDirectory:nil];    
    NSString *filePath = [pdfs lastObject]; assert(filePath != nil); // Path to last PDF file

    ReaderDocument *readerDocument = [ReaderDocument withDocumentFilePath:filePath password:phrase];    
    if (readerDocument != nil) // Must have a valid ReaderDocument object in order to proceed with things
    {
        ReaderViewController *rViewController = [[ReaderViewController alloc] initWithReaderDocument:readerDocument];        
        rViewController.delegate = self; // Set the ReaderViewController delegate to self              

        [self presentModalViewController:rViewController animated:NO];        
    } 
}

但这导致了一个尴尬的演示

enter image description here

任何人都可以提出这里有什么问题,提前谢谢..

4 个答案:

答案 0 :(得分:2)

在您的屏幕截图中,我无法确定您的拆分视图控制器左侧和右侧(详细视图)位于何处。更改视图的背景颜色以区分位置。好像你遇到了问题。

无论如何,您可以尝试使用splitView而不是Detail来呈现模态视图控制器。

[splitViewController presentModalViewController:rViewController animated:NO];

答案 1 :(得分:2)

我相信这里的技巧是改变你想以模态方式显示的视图控制器的modalPresentationStyle(以及可选的modalTransitionStyle):

    ReaderViewController *rViewController = [[ReaderViewController alloc] initWithReaderDocument:readerDocument];        
    rViewController.delegate = self; // Set the ReaderViewController delegate to self              

    rViewController.modalPresentationStyle = UIModalPresentationFullScreen;
    rViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;     
    [self presentViewController:rViewController animated:YES completion:nil];

答案 2 :(得分:1)

我遇到了同样的问题(在iOS 5.1中)。将modalPresentationStyle设置为UIModalPresentationPageSheet,它应该按预期工作。

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    rViewController.modalPresentationStyle = UIModalPresentationPageSheet;
    rViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
}

答案 3 :(得分:0)

我发现你提供的分割视图大小如cetralArea.frame.size.width

而不是简单地直接给出你想要给Splitview的大小。

希望它对你有用。