gpt4 book ai didi

ios - QuickLook 使用 UINavigationController 在模式中预览文件

转载 作者:行者123 更新时间:2023-11-29 01:29:06 25 4
gpt4 key购买 nike

我想使用 Quicklook 预览应用中的一些文档。

有一个 fileUrls 数组,我想在 UITableView 中显示所有文件名。当用户单击文件名时,将加载所选文件。

这里的问题是,委托(delegate)在 viewDidLoad 时自动触发,并检查所选文件,但我想将 Quicklook-Controller 推送到我现有的 UINavigationController。

生病时尝试:

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!)
}

它崩溃了,因为(当然)没有选择该文件。当我使用额外的 viewController 时,将 currentFile 推送到新的 ViewController,然后在 ViewDidLoad 上打开文件:

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

Controller 以全屏方式显示,但我更喜欢在现有的 UINavigationController 中显示我的文件。有没有办法做到这一点?我是否需要额外的 ViewController,或者是否可以简单地将文件推送到我的 UINavigationcontroller 中的 Quicklookcontroller?

更新:

这是我的 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)

将工作,因为 presentViewController 使用 modalPresentationStyle

已编辑

这应该可行

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

关于ios - QuickLook 使用 UINavigationController 在模式中预览文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33653506/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com