繁体   English   中英

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

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

我有一个正在使用Xcode7Swift2iOS项目。 我有一个保存为ParsePDF 它保存到名为IncomingRecipeParse Class 在这个Class是一FileName用柱typeString 它还有一个名为PDFData的列,类型为PFFile 我想要这样,当用户单击TableViewCell它会选择一个新的View Controller并在WebView显示PDF

当前,这些fileNames位于TableView 我有一个选择,可以通过WebView转到View Controller 它沿的名称通过fileNameTableViewCell作为一个Global variable

我对要解析的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()

        }

    }

}

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 Controller上的WebView 我不知道如何将所有这些信息都放入要与WebView一起使用的URL中。 我看着这里 ,试图与我一起实现这一目标,但没有成功。 谢谢。

不要只用

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

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

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

暂无
暂无

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

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