簡體   English   中英

PreviewController PreviewItemAt不被調用。 iOS 10,Swift 3,模擬器

[英]previewController previewItemAt not being called. iOS 10, swift 3, simulator

我在情節提要中創建了一個新的視圖控制器。 將其連接到ListViewController。 ListViewController將正確的數據填充到aboutDict[String:Any] fileURLs[]並使用func numberOfPreviewItems(in: QLPreviewController) -> Int調用fileURLs[]調試器顯示fileURLs[]符合預期:

self.fileURLs的打印描述:▿1個元素-0:file:/// Users / kent / Library / Developer / CoreSimulator / Devices / 5E23825C-DF99-455A-BEB1-F73398E7759F / data / Containers / Bundle / Application / 307ED7DF- C07C-4C0A-BA78-938BABE7C22C / WINSystemInfo.app / ID-51A_E_PLUS2.pdf`

但是func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItemfunc previewController(_ controller: QLPreviewController, shouldOpen url: URL, for item: QLPreviewItem) -> Bool不調用func previewController(_ controller: QLPreviewController, shouldOpen url: URL, for item: QLPreviewItem) -> Bool

我得到了一個不錯的ViewController,它以正確的后退按鈕名稱被推入導航堆棧,並帶有一個灰色頁面,其中心文字為“無預覽文件”。

在按下“后退”按鈕時,將func previewControllerWillDismiss(_ controller: QLPreviewController)函數。 因此,正在調用某些委托和數據源功能。

我一定錯過了一些簡單的事情...

我在下面附加了我的類FileViewController.swift:

class FileViewController: QLPreviewController, QLPreviewControllerDelegate, QLPreviewControllerDataSource {

    var aboutDict = [String: Any]()

    // QuickLook data
    var fileURLs = [QLPreviewItem]()

    // MARK: - Lifecycle

    override func viewDidLoad() {
        super.viewDidLoad()
        let filename = aboutDict["filename"] as! String?
        let filetype = aboutDict["filetype"] as! String?

        title = aboutDict["title"] as! String?
        dataSource = self
        delegate = self

        if let fileUrl = Bundle.main.url(forResource: filename, withExtension: filetype, subdirectory: nil, localization: nil)
        {
            let filePreview = fileUrl as QLPreviewItem
            fileURLs.append(filePreview)
        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // MARK: - Preview controller datasource  functions

    func numberOfPreviewItems(in: QLPreviewController) -> Int {
        return fileURLs.count
    }

    func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem {
        return fileURLs[index]
    }

    // MARK: - Preview controller delegate functions

    func previewControllerWillDismiss(_ controller: QLPreviewController) {
        debug("previewControllerWillDismiss")
    }

    func previewController(_ controller: QLPreviewController, shouldOpen url: URL, for item: QLPreviewItem) -> Bool {
        return true
    }
}

我想念什么?

謝謝。

我只是遇到了這個問題,這僅僅是因為我忘記了在QLPreviewController上設置數據源...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM