iphone - 如何在 PhoneGap 中创建 viewController 以与主视图一起使用

标签 iphone ios cordova

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

我已经创建了 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

并尝试预览文件

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!

我可以设置 Root View Controller

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

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

最佳答案

问题已解决

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

关于iphone - 如何在 PhoneGap 中创建 viewController 以与主视图一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15830016/

相关文章:

android - 为什么一个非常简单的 phonegap 应用程序使用移动数据计划?

ios - NSUndoManager : revert all the functionality of method

ios - 有没有办法在 iOS 模拟器上使用苹果的 Touch ID(指纹扫描仪)?

ios - SKProductsRequest - 如何处理超时/连接错误?

ios - 使用 setRowHeight 函数设置 UITableView 单元格高度和 tableView : heightForRowAtIndexPath: function? 之间有什么区别

ios - UITextView 对齐文本垂直居中

ios - iTunes Connect App Update 版本是否适用于所有国家/地区?

android - android 上的 phonegap 说 : Not allowed to load local resource: file:///android_asset/www/app/fb. js

android - 为 ios 和 android 删除 phonegap 中的启动画面

iphone - 释放 Objective-C block 中的对象