我想用[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 的主视图。我怎样才能做到这一点?