简体   繁体   English

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

[英]View Parse PFFile PDF in WebView using Xcode7 and Swift 2

I have an iOS project I'm working on using Xcode7 and Swift2 . 我有一个正在使用Xcode7Swift2iOS项目。 I have a PDF that is saving to Parse . 我有一个保存为ParsePDF It is saving to a Parse Class called IncomingRecipe . 它保存到名为IncomingRecipeParse Class In this Class is a FileName column with type as a String . 在这个Class是一FileName用柱typeString It also has a column called PDFData and is type PFFile . 它还有一个名为PDFData的列,类型为PFFile I want it so when the user clicks on a TableViewCell it segues to a new View Controller and displays the PDF in a WebView . 我想要这样,当用户单击TableViewCell它会选择一个新的View Controller并在WebView显示PDF

Currently these fileNames are in a TableView . 当前,这些fileNames位于TableView I have a segue that goes to the View Controller with the WebView . 我有一个选择,可以通过WebView转到View Controller It passes along the name of the fileName from the TableViewCell as a Global variable . 它沿的名称通过fileNameTableViewCell作为一个Global variable

My query for the data for the TableView code for parse is: 我对要解析的TableView代码的数据的query是:

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()

        }

    }

}

The TableView loads the fileName as: 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
}

I have the code for passing the selected cell fileName to a Global variable as: 我有用于将所选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)")

        }

    }

}

How can I get the PFFile of the PDA and display it in the WebView on the other View Controller ? 如何获取PDAPFFile并将其显示在另一个View Controller上的WebView I can't figure out how to get all of this into a URL to be used with the WebView . 我不知道如何将所有这些信息都放入要与WebView一起使用的URL中。 I looked here and tried to implement this with mine, with no success. 我看着这里 ,试图与我一起实现这一目标,但没有成功。 Thank you. 谢谢。

Don't just save the file name with 不要只用

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

save the whole list of PFObject s. 保存PFObject的整个列表。 These objects will contain the file name (that you can use for the table view) and the PFFile reference (that you can use on drill down). 这些对象将包含文件名(可用于表视图)和PFFile引用(可在向下钻取时使用)。 Also, you don't appear to, but you shouldn't pass by global. 另外,您似乎没有出现,但您不应该绕过全局。 It just looks like you're passing the file name in the segue. 看起来您好像在segue中传递了文件名。

Instead of passing the file name you should pass the whole PFObject . 而不是传递文件名,您应该传递整个PFObject Then, in the destination view controller you can extract the PFFile reference and the URL it contains. 然后,在目标视图控制器中,您可以提取PFFile引用及其包含的URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM