Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

presentModalViewController in UISplitViewControllers detailView not presenting the view in full screen

I have added the UISplitViewController view in my mainViewControllers view, the code is below.

    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];

now what I want is to present a ViewController from the DetailView of the UISplitViewController I am trying to do it as below inside the DetailViewControllers Click Me! buttons click.

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];        
    } 
}

but this is resulting in an awkward presentation

enter image description here

can anyone suggest what is the problem here, thanks in advance..

like image 612
Shashank Avatar asked Apr 24 '12 12:04

Shashank


3 Answers

In your screenshots I can't really tell where is your split view controller left side and right side (detail view) located. Change background colors of the views to distinguish positions. Seems you are having problems with them.

Anyways, you can try presenting the modal view controller from the splitView instead of the Detail.

[splitViewController presentModalViewController:rViewController animated:NO];
like image 128
Martin Garcia Avatar answered Oct 21 '22 15:10

Martin Garcia


I believe the trick here is changing the modalPresentationStyle (and optionally modalTransitionStyle) of the view controller that you want to display modally:

    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];
like image 34
pdriegen Avatar answered Oct 21 '22 14:10

pdriegen


I had the same problem (in iOS 5.1). Set the modalPresentationStyle to UIModalPresentationPageSheet and it should work as expected.

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    rViewController.modalPresentationStyle = UIModalPresentationPageSheet;
    rViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
}
like image 1
Mongo Avatar answered Oct 21 '22 16:10

Mongo