首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >对UIDocumentInteraction中的<QLRemotePreviewContentController: 0x7d19a000>开始/结束外观转换的不平衡调用

对UIDocumentInteraction中的<QLRemotePreviewContentController: 0x7d19a000>开始/结束外观转换的不平衡调用
EN

Stack Overflow用户
提问于 2014-11-19 14:25:48
回答 1查看 1.7K关注 0票数 0

我正在尝试通过在phonegap应用程序中使用UIDocumentInteractionController来加载设备中的文件。我已经做到了以下几点。

代码语言:javascript
复制
#import <Foundation/Foundation.h>
#import <QuickLook/QuickLook.h>

@interface FileViewer : UIViewController <UIDocumentInteractionControllerDelegate>

@end

@implementation FileViewer

- (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
{
    [self viewDidLoad];
    // Do any additional setup after loading the view.
}

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

@end

在Launcher.m中,我通过以下方式显示文件:

代码语言:javascript
复制
    CDVViewController* mainController = (CDVViewController*)[ super viewController ];
        UIDocumentInteractionController *documentInteractionController =    [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:fileLocation]];
        FileViewer *vController = [[FileViewer alloc]init];
        [mainController addChildViewController:vController];
        documentInteractionController.delegate = vController;
       [documentInteractionController presentPreviewAnimated:YES];

这是通过给出错误消息:“不鼓励在分离的视图控制器上呈现视图控制器。不平衡调用QLRemotePreviewContentController的开始/结束外观转换”造成的。

提前感谢!!

EN

回答 1

Stack Overflow用户

发布于 2014-11-26 20:16:50

我已经通过下面的方式解决了我的问题。这可能不是最好的方法,所以请也建议最好的方法。

代码语言:javascript
复制
@interface Launcher : CDVPlugin<UIDocumentInteractionControllerDelegate>
@property (strong, nonatomic)UIViewController *navigatorController;
@property (strong, nonatomic)Launcher *launcher;
@property (strong, nonatomic)NSString *callbackId;
-(void)openFile:(CDVInvokedUrlCommand*)command;

@end

#import "Launcher.h"
#import "FileViewer.h"
#import<QuickLook/QuickLook.h>
#import <MobileCoreServices/MobileCoreServices.h>

@implementation Launcher

-(void)openFile:(CDVInvokedUrlCommand*)command{
    CDVPluginResult *pluginResult = nil;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSDictionary *params = [command.arguments objectAtIndex:0];
    NSString *file = [params objectForKey:@"message"];
    NSString *fileLocation = [documentsDirectory stringByAppendingFormat:@"/%@",file];

    if (![fileLocation isEqual:[NSNull null]]) {
        @try {
            self.launcher = self;
            CDVViewController *viewController = [CDVViewController new];
            viewController.wwwFolderName = @"www";
            viewController.startPage = @"main.html";  // page contains listview showing name of files
            self.navigatorController = viewController;
            UIDocumentInteractionController *documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:fileLocation]];
            [[UIApplication sharedApplication].keyWindow setRootViewController:self.navigatorController];
            documentInteractionController.delegate = self;
            [documentInteractionController presentPreviewAnimated:YES];    
        }
        @catch (NSException *exception) {
            NSLog(@"dd : %@",[exception reason]);
        }

    }
    pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
- (UIViewController *)documentInteractionControllerViewControllerForPreview:  (UIDocumentInteractionController *)controller
{
    return self.navigatorController;
}

- (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller
{
    [[UIApplication sharedApplication].keyWindow setRootViewController:self.navigatorController];
    self.launcher = nil;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27010351

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档