Ios 使用Xcode7和Swift 2在WebView中查看解析PDF文件

Ios 使用Xcode7和Swift 2在WebView中查看解析PDF文件,ios,swift,parse-platform,uiwebview,xcode7,Ios,Swift,Parse Platform,Uiwebview,Xcode7,我有一个iOS项目,我正在使用Xcode7和Swift2。我有一个PDF正在保存到Parse。它正在保存到一个名为IncomingRecipe的Parse类中。在这个类中是一个文件名列,其中类型为字符串。它还有一个名为PDFData的列,类型为PFFile。我希望这样,当用户单击TableViewCell时,它会切换到一个新的视图控制器,并在WebView中显示PDF 目前,这些文件名位于表格视图中。我有一个序列,通过WebView进入视图控制器。它将表格视图单元格中的文件名作为全局变量传递 我

我有一个
iOS
项目,我正在使用
Xcode7
Swift2
。我有一个
PDF
正在保存到
Parse
。它正在保存到一个名为
IncomingRecipe
Parse
类中。在这个
类中
是一个
文件名
列,其中
类型
字符串
。它还有一个名为
PDFData
的列,类型为
PFFile
。我希望这样,当用户单击
TableViewCell
时,它会切换到一个新的
视图控制器
,并在
WebView
中显示
PDF

目前,这些
文件名
位于
表格视图中
。我有一个序列,通过
WebView
进入
视图控制器。它将
表格视图单元格中的
文件名
作为
全局变量
传递

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

        }

    }

}
TableView
文件名加载为:

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
}
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)")

        }

    }

}
我有将选定的
单元格
文件名
传递给
全局变量的代码,如下所示:

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
}
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)")

        }

    }

}

如何获取
PDA
PFFile
,并将其显示在另一个
视图控制器上的
WebView
中?我不知道如何将所有这些内容都放到
URL
中,以便与
WebView
一起使用。我看了看,试图用我的实现,但没有成功。谢谢。

不要只保存文件名

self.fileName.append(object["fileName"] as! String)
保存
PFObject
s的整个列表。这些对象将包含文件名(可用于表视图)和
PFFile
引用(可用于向下钻取)。而且,你看起来没有,但你不应该路过。看起来您正在传递序列中的文件名


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

我是新手。我如何通过整个对象?我是否创建了一个具有PFObject类型的全局变量,然后将其设置为TableView控制器中的当前PFObject,然后再切换到WebView?我按照您的建议保存了整个列表。请查看我的编辑。从不使用全局变量!与名称完全相同,只需更改变量类型,只需保存PFObject数组,无需单独中断,只需稍加调整即可。谢谢你给了我这个想法。