简体   繁体   English

QuickLook使用UINavigationController预览模式中的文件

[英]QuickLook to preview files in an modal with UINavigationController

I would like to use Quicklook to preview some documents in an app. 我想使用Quicklook预览应用程序中的某些文档。

There is an array of fileUrls, and i would like to display all the filenames in an UITableView. 有一个fileUrls数组,我想在UITableView中显示所有文件名。 When the user clicks on an fileName, ill load the selected file. 当用户单击fileName时,将不加载所选文件。

The problem here is, that the delegate fires automatically when the viewDidLoad, and checks for the selected file, But ill want to push the Quicklook-Controller to my existing UINavigationController. 这里的问题是,委托在viewDidLoad时自动触发,并检查所选文件,但是我想将Quicklook-Controller推送到我现有的UINavigationController中。

When ill try with: 生病时尝试:

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    currentFile = TaskFiles[indexPath.row]
    self.navigationController?.pushViewController(preview, animated: false)
}

func numberOfPreviewItemsInPreviewController(controller: QLPreviewController) -> Int {
    return 1
}

func documentsDirectoryURL() -> NSURL {
    let manager = NSFileManager.defaultManager()
    let URLs = manager.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)
    return URLs[0]
}

func previewController(controller: QLPreviewController, previewItemAtIndex index: Int) -> QLPreviewItem {
    return documentsDirectoryURL().URLByAppendingPathComponent(currentFile!.url!)
}

It crashes, because the file is (of course) not selected. 它崩溃,因为(当然)未选择该文件。 When ill use an additional viewController, and push the currentFile to the new ViewController, and open the file on ViewDidLoad with: 生病时使用其他viewController,并将currentFile推送到新的ViewController,然后使用以下命令在ViewDidLoad上打开文件:

    let preview = QLPreviewController()
    presentViewController(preview, animated: true, completion: nil)

The Controller is presented fullscreen, but ill prefer to show my file in my existing UINavigationController. 控制器以全屏显示,但我不希望在我现有的UINavigationController中显示我的文件。 Is there a way to accomplish that? 有没有办法做到这一点? Do i need an additional ViewController, or can ill simple push a file to my Quicklookcontroller IN my UINavigationcontroller? 我是否需要一个额外的ViewController,还是可以简单地将文件推送到UINavigationcontroller中的Quicklookcontroller中?

Update: 更新:

This is my ViewDidLoad: 这是我的ViewDidLoad:

class ModalFormCaptureFilePreviewViewController: UIViewController,     QLPreviewControllerDataSource, QLPreviewControllerDelegate {

var currentFile:Files?
let preview = QLPreviewController()

override func viewDidLoad() {
    super.viewDidLoad()
    preview.dataSource = self
    showViewController(preview, sender: self)
}
let preview = QLPreviewController()
showViewController(preview, sender: self)

will work, as presentViewController uses the modalPresentationStyle 会工作,因为presentViewController使用modalPresentationStyle

Edited 已编辑

This should work 这应该工作

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 
    currentFile = TaskFiles[indexPath.row]
    let preview = QLPreviewController()
    preview.dataSource = self
    self.navigationController?.pushViewController(preview, animated: false)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM