[英]View Parse PFFile PDF in WebView using Xcode7 and Swift 2
我有一个正在使用Xcode7
和Swift2
的iOS
项目。 我有一个保存为Parse
的PDF
。 它保存到名为IncomingRecipe
的Parse
Class
。 在这个Class
是一FileName
用柱type
为String
。 它还有一个名为PDFData
的列,类型为PFFile
。 我想要这样,当用户单击TableViewCell
它会选择一个新的View Controller
并在WebView
显示PDF
。
当前,这些fileNames
位于TableView
。 我有一个选择,可以通过WebView
转到View Controller
。 它沿的名称通过fileName
从TableViewCell
作为一个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()
}
}
}
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
}
我有用于将所选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)")
}
}
}
如何获取PDA
的PFFile
并将其显示在另一个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.