包含collectionView的表视图XIB内的当前DocumentInteractionController

时间:2018-11-12 07:33:01

标签: ios swift uitableview uidocumentinteractioncontroller

我正在尝试加载包含tableview xib的{​​{1}}。 collectionView包含要下载和打开的文件列表。

collectionView
  

self.dic.presentOpenInMenu(来自:rect,在:self.view中,动画:true)   类型“ CommentsCell”的值没有成员“ view”

Tableview XIB设计:

Tableview XIB design file

2 个答案:

答案 0 :(得分:1)

viewController对象传递到UITableViewCell并用

替换行
self.dic.presentOpenInMenu(from: rect, in: vc.view, animated: true)

在ViewController中:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    .....
    cell.vc = self
}

在CommentsCell中:

class CommentsCell: UITableViewCell, UICollectionViewDelegate, UICollectionViewDataSource, UIDocumentInteractionControllerDelegate {

    weak var vc: UIViewController!

    ........

    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        let fileUrl = imgCollection[indexPath.row].fileUrl?.absoluteString
        let url = URL(string: Api.domain + fileUrl!)

        let destination = DownloadRequest.suggestedDownloadDestination(for: .documentDirectory)

        sharedAFManager.AFManager.download(url!, to: destination)
            .downloadProgress(closure: { _ in
                SVProgressHUD.show()
            }).response(completionHandler: { (downloadResponse) in
                SVProgressHUD.dismiss()
                self.dic.url = downloadResponse.destinationURL
                self.dic.uti = downloadResponse.destinationURL!.uti
                let rect = CGRect(x: 0, y: 0, width: 100, height: 100)
                self.dic.presentOpenInMenu(from: rect, in: vc.view, animated: true)
            })
    }
}

答案 1 :(得分:1)

您不能通过UIView呈现OpenInMenu。您需要使用UIviewContoller的实例来呈现ViewController,因此您可以简单地在tableview单元格中传递View Controller对象,或使用下面的uiview扩展

extension UIView {

    var parentViewController: UIViewController? {
        var parentResponder: UIResponder? = self
        while parentResponder != nil {
            parentResponder = parentResponder!.next
            if let viewController = parentResponder as? UIViewController {
                return viewController
            }
        }
        return nil
    }

}

和presentOpenInMenu

self.parentViewController?.presentOpenInMenu(from: rect, in: self.view, animated: true)