【问题标题】:View Parse PFFile PDF in WebView using Xcode7 and Swift 2使用 Xcode7 和 Swift 2 在 WebView 中查看 Parse PFFile PDF
【发布时间】:2016-01-14 15:00:26
【问题描述】:

我正在使用Xcode7Swift2 处理一个iOS 项目。我有一个PDF 正在保存到Parse。它正在保存到名为IncomingRecipeParse Class。在这个Class 是一个FileName 列,type 是一个String。它还有一个名为PDFData 的列,类型为PFFile。我想要它,所以当用户点击TableViewCell 时,它会转到新的View Controller 并在WebView 中显示PDF

目前这些fileNames 位于TableView 中。我有一个转到View ControllerWebView 的segue。它将fileName 的名称从TableViewCell 传递为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 一起使用。我查看了here 并尝试用我的方法实现这一点,但没有成功。谢谢。

【问题讨论】:

    标签: ios swift parse-platform uiwebview xcode7


    【解决方案1】:

    不要只用

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

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

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

    【讨论】:

    • 我是新手。如何传递整个 PFObject?我是否创建了一个类型为 PFObject 的全局变量,然后将其设置为 TableView 视图控制器中的当前 PFObject,然后再将其设置为 WebView ?
    • 我按照您的建议保存了整个列表。请查看我的编辑。
    • 永远不要全局变量!做的和名字一模一样,只是改变变量类型
    • 只保存一个PFObject数组,不需要拆开
    • 做了一些调整,它奏效了。感谢您提出我需要做的事情的想法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多