使用 Xcode7 和 Swift 在 WebView 中查看 Parse PFFile PDF 2

View Parse PFFile PDF in WebView using Xcode7 and Swift 2

我有一个 iOS 项目,正在使用 Xcode7Swift2。我有一个正在保存到 ParsePDF。它正在保存到名为 IncomingRecipeParse Class。在此 Class 中有一个 FileName 列,其中 type 作为 String。它还有一个名为 PDFData 的列,类型为 PFFile。我想要它,所以当用户单击 TableViewCell 时,它会转到新的 View Controller 并在 WebView.

中显示 PDF

目前这些 fileNamesTableView 中。我有一个使用 WebView 转到 View Controller 的 segue。它将 TableViewCellfileName 的名称作为 Global variable.

传递

我的 query TableView 解析代码的数据是:

var fileName = [String]()
var PDFData = [PFFile]()

var getRecipeQuery = PFQuery(className: "IncomingRecipe")

// Match the query with only items that the current user uploaded
getRecipeQuery.whereKey("userId", equalTo: appUserId)
getRecipeQuery.findObjectsInBackgroundWithBlock { (objects, error) -> Void in

    // Check to see if 'objects' exist
    if let objects = objects {

        for object in objects {

            // An AnyObject that needs to be cast as a String
            var recipeName = object["fileName"] as! String

            self.fileName.append(object["fileName"] as! String)

            self.objectid.append(object["objectid"] as! String)

            self.userId.append(object["userId"] as! String)

            self.PDFData.append(object["PDFData"] as! PFFile)

            self.myFilesTable.reloadData()

        }

    }

}

TableViewfileName 加载为:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cellIdentifier = "PDFTableViewCell"

    let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! PDFTableViewCell

    cell.textLabel?.text = fileName[indexPath.row]

    return cell
}

我有将选定的 cell fileName 传递给 Global variable 的代码:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

    if segue.identifier == "ItemView" {

        let savedRecipedView = segue.destinationViewController as! PDFItemViewController

        if let selectedRecipeCell = sender as? PDFTableViewCell {

            let indexPath = myFilesTable.indexPathForCell(selectedRecipeCell)!

            viewingPDFRecipe = fileName[indexPath.row]

            print("Sending Click: \(viewingPDFRecipe)")

        }

    }

}

如何获取 PDAPFFile 并将其显示在另一个 View ControllerWebView 中?我不知道如何将所有这些都放入 URL 中以与 WebView 一起使用。我查看了 并尝试用我的来实现它,但没有成功。谢谢。

不要只用

保存文件名
self.fileName.append(object["fileName"] as! String)

保存 PFObject 的整个列表。这些对象将包含文件名(可用于 table 视图)和 PFFile 引用(可用于下钻)。此外,你似乎没有,但你不应该通过全球。看起来你在 segue 中传递了文件名。

您应该传递整个 PFObject,而不是传递文件名。然后,在目标视图控制器中,您可以提取 PFFile 引用及其包含的 URL。