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

标签 ios swift parse-platform uiwebview xcode7

我正在使用 Xcode7Swift2 开发一个 iOS 项目。我有一个 PDF 正在保存到 Parse。它保存到名为 IncomingRecipeParse Class 中。在此Class 中有一个FileName 列,其中typeString。它还具有名为 PDFData 的列,类型为 PFFile。我希望这样,当用户单击 TableViewCell 时,它会转到新的 View Controller 并在 WebView< 中显示 PDF/.

目前这些fileNames位于TableView中。我有一个使用 WebView 转到 View Controller 的 Segue。它将 TableViewCell 中的 fileName 名称作为全局变量传递。

我的查询用于解析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()

        }

    }

}

TableView 加载 fileName 为:

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
}

我有将所选单元格 fileName传递给全局变量的代码,如下所示:

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 Controller上的WebView中>?我不知道如何将所有这些都放入 URL 中以与 WebView 一起使用。我看了here并尝试用我的实现这一点,但没有成功。谢谢。

最佳答案

不要只用

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

保存PFObject的整个列表。这些对象将包含文件名(可用于 TableView )和 PFFile 引用(可在向下钻取时使用)。另外,你似乎没有,但你不应该通过全局。看起来您只是在 segue 中传递文件名。

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

关于ios - 使用 Xcode7 和 Swift 2 在 WebView 中查看 Parse PFFile PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34792696/

相关文章:

ios - FileManager.default.enumerator 不返回任何文件

ios - 键盘出现时输入文本失去焦点 - iOS PhoneGap 应用程序

ios - Mapbox WMS 对 iOS 的支持

ios - 频繁使用计算属性访问对象是否会影响性能?

ios - 在 Xcode 中,有没有办法设置一个表,它不是用于 UI,而是用于处理数据的 'engine'

iOS swift parse + 如何检查电子邮件是否已存在于数据库中

javascript - 解析: Compound Query on Followers times out

ios - 为什么我不能停止 UIPageViewController 中的卷页动画

ios - 在我的应用程序中支持 iPad 和 iPhone 的最佳方法是什么?

javascript - 使用 PFCloud 代码推送通知