0

我想用[UIDocumentInteractionController presentPreviewAnimated];打开文件

我已经创建了视图控制器

@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

并尝试预览文件

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

并得到错误:

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

我可以设置根视图控制器

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

但我不想使用新视图。我需要使用PhoneGap 的主视图。我怎样才能做到这一点?

4

1 回答 1

1

问题已经解决了

CDVViewController* mainController = (CDVViewController*)[ super viewController ]; 
[mainController addChildViewController:vController];
于 2013-04-05T10:12:34.097 回答