2016-11-14 34 views
1

我正在開發一個iOS應用程序,向用戶顯示大量不同的文件。從視頻和音頻文件到html和Office/iWorks文件。我已經子類化QLPreviewController,並希望用它來顯示這些文件中的一部分。我創建對象,將它傳遞給文件的URL,設置ViewController視圖的框架來替換父視圖控制器中的webView框架。 :iOS 10,QLPreviewViewController不顯示文件

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的視圖。

回答

0

好的我想發佈我遇到的問題的答案。問題是我沒有將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帕特爾