【发布时间】:2018-10-14 09:04:18
【问题描述】:
我在我的视图控制器中嵌入了一个QLPreviewController 作为子视图控制器,并为其设置了委托和数据源:
qlPreviewController.delegate = self
qlPreviewController.dataSource = self
在我的viewDidLoad 中,我正在下载一个远程文档。下载完成后,我重新加载QLPreviewController 以显示该文档。这工作正常。
现在,我想同时显示多个文档。因此,我下载了多个文档,设置了一个数组,然后重新加载了QLPreviewController。
这里是实现的数据源方法:
func numberOfPreviewItems(in controller: QLPreviewController) -> Int {
print("count:", downloadedDocuments.count)
return downloadedDocuments.count
}
func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem {
print("\(index+1)/\(downloadedDocuments.count), id:", downloadedDocuments[index].id)
return downloadedDocuments[index].localURL as QLPreviewItem
}
最终的结果是只显示一个文档,这是数组中的第一个文档。我添加了上面的打印语句,以验证downloadedDocuments 数组中有多个文档。它打印:
count: 5
1/5, id: 251
如您所见,它只调用了一次previewItemAtIndex,索引仍然是0。
这是为什么?我还需要设置什么吗?
【问题讨论】:
标签: ios swift qlpreviewcontroller