CruorVult
CruorVult

Reputation: 823

How to create viewController in PhoneGap to work with main view

I want to open file with [UIDocumentInteractionController presentPreviewAnimated];

I've created view controller

@interface FileViewController : UIViewController <UIDocumentInteractionControllerDelegate>

    @end



#import "FileViewController.h"

@interface FileViewController ()

@end

@implementation FileViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}   

- (UIViewController *) documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller {
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

And trying to preview the file

UIDocumentInteractionController *controller = [UIDocumentInteractionController  interactionControllerWithURL:fileURL];
vController = [[FileViewController alloc] init];
controller.delegate = vController;
[controller presentPreviewAnimated:YES];

And get error:

Warning: Attempt to present <QLPreviewController: 0x1e56e0a0> on <FileViewController: 0x1ec3e000> whose view is not in the window hierarchy!

I may set root view controller

[[[[UIApplication sharedApplication] delegate] window] setRootViewController:vController];

But I dont want to use new view. I need to use the PhoneGap's main view. How can I do this?

Upvotes: 0

Views: 935

Answers (1)

CruorVult
CruorVult

Reputation: 823

The problem is solved

CDVViewController* mainController = (CDVViewController*)[ super viewController ]; 
[mainController addChildViewController:vController];

Upvotes: 1

Related Questions