【问题标题】:iOS 10, QLPreviewViewController is not displaying filesiOS 10,QLPreviewViewController 不显示文件
【发布时间】:2016-11-14 15:49:43
【问题描述】:

我正在开发一个向用户显示大量不同文件的 iOS 应用。从视频和音频文件到 html 和 Office/iWorks 文件。我将 QLPreviewController 子类化,并希望使用它来显示其中一些文件。我创建对象,将文件的 url 传递给它,设置 ViewController 的视图框架以替换父视图控制器中的 webView 的框架。 :

else if (QuickLookViewController.canOpenFile(previewItem: contentUrl as NSURL)) {

    hideControls()
    quickLook.contentURLs = [contentUrl as NSURL]

    //add the QuickLookController's view to content display using webview's frame
    self.view.addSubview(quickLook.view)

    quickLook.view.frame = webview!.frame
    quickLook.reloadData()

使用视图调试层次工具,它显示正确设置的视图,以及设置 quickLook.backgroundColor = UIColor.black 只是为了测试。

所以我认为可能是访问下载和存储的文件有问题,所以在QuickLookController的viewDidLoad中我添加了一些测试以确保文件在那里:

super.viewDidLoad()
print("\nContent URL: \(contentURLs[0])")
print("\nContent URL Path: \(contentURLs[0].path!)")

self.delegate = self
self.dataSource = self
var error : NSError?

print("\nis reachable: \(contentURLs[0].checkResourceIsReachableAndReturnError(&error))")
if (error != nil) {
    print("is reachable error -> \(error.debugDescription)")
}
print("\ndoes exist: \(FileManager.default.fileExists(atPath: contentURLs[0].path!))")
print("\nCan open: \(QuickLookViewController.canOpenFile(previewItem: contentURLs[0]))")

并且日志语句按我的预期出现:

Content URL: file:///var/mobile/Containers/Data/Application/B9D5C288-F889-4513-941E-2564F1C12F02/Documents/588c5a1e-dffe-47a8-9824-bc19463aafc2/d88a8dd5-40d1-4fdb-adf3-10fce1f6bf1f/fd73c162-5ac3-4269-8573-9c0b61bef7a7/fd73c162-5ac3-4269-8573-9c0b61bef7a7.pages

Content URL Path: /var/mobile/Containers/Data/Application/B9D5C288-F889-4513-941E-2564F1C12F02/Documents/588c5a1e-dffe-47a8-9824-bc19463aafc2/d88a8dd5-40d1-4fdb-adf3-10fce1f6bf1f/fd73c162-5ac3-4269-8573-9c0b61bef7a7/fd73c162-5ac3-4269-8573-9c0b61bef7a7.pages

is reachable: true

does exist: true

Can open: true

我什至在 viewDidLoad 中使用了一个断点来检查 quickLook 的超级视图是否使用 'po self.view.superview!.frame' 作为 llbd 语句设置,并再次收到我预期的输出。

我在应用程序中的另一个视图堆栈中使用了同一个类,它显示了被点击的文件,所以它对我来说没有多大意义。这两种用途之间的唯一区别是,第二个我在以模态方式呈现的 viewController 中呈现 quickLook 的视图。

【问题讨论】:

    标签: ios swift qlpreviewcontroller


    【解决方案1】:

    好的,我想发布我遇到的问题的答案。问题是我没有将 quickLook 视图控制器添加到具有父子关系的 ContentDisplayViewController 中。所以添加我想要的视图的更新代码如下所示:

    //create the parent-child relationship for the view controllers
    self.addChildViewController(quickLook)
    
    //give the view it's frame
    quickLook.view.frame = webview!.frame
    
    //add the view and call the child's didMove() method.
    self.view.addSubview(quickLook.view)
    quickLook.didMove(toParentViewController: self)
    

    这个问题给了我答案: Add child view controller to current view controller

    给我一​​些阅读材料,感谢@Piyush Patel 的帖子

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-21
      • 1970-01-01
      相关资源
      最近更新 更多