11

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..

Shashank
  • 1,087
  • 1
  • 14
  • 26

4 Answers4

2

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];
Martin Garcia
  • 345
  • 5
  • 14
  • Hi Martin, thanks for reply but this doesn't worked. presenting the view controller using splitviewcontroller is showing nothing. – Shashank Apr 24 '12 at 15:58
2

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];
pdriegen
  • 2,019
  • 1
  • 13
  • 19
1

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;
}
Mongo
  • 2,674
  • 1
  • 20
  • 22
0

What i found is you are giving splitview size like cetralArea.frame.size.width.

Instead of that simply give directly size that you want to give to the Splitview.

Hope it will work for you.

Mayur Prajapati
  • 5,454
  • 7
  • 41
  • 70