[英]QuickLook to preview files in an modal with UINavigationController
我想使用Quicklook預覽應用程序中的某些文檔。
有一個fileUrls數組,我想在UITableView中顯示所有文件名。 當用戶單擊fileName時,將不加載所選文件。
這里的問題是,委托在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)
控制器以全屏顯示,但我不希望在我現有的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)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.