[英]View Parse PFFile PDF in WebView using Xcode7 and Swift 2
I have an iOS
project I'm working on using Xcode7
and Swift2
. 我有一个正在使用Xcode7
和Swift2
的iOS
项目。 I have a PDF
that is saving to Parse
. 我有一个保存为Parse
的PDF
。 It is saving to a Parse
Class
called IncomingRecipe
. 它保存到名为IncomingRecipe
的Parse
Class
。 In this Class
is a FileName
column with type
as a String
. 在这个Class
是一FileName
用柱type
为String
。 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
. 它沿的名称通过fileName
从TableViewCell
作为一个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: 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
}
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
? 如何获取PDA
的PFFile
并将其显示在另一个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.