我正在使用 Xcode7
和 Swift2
开发一个 iOS
项目。我有一个 PDF
正在保存到 Parse
。它保存到名为 IncomingRecipe
的 Parse
Class
中。在此Class
中有一个FileName
列,其中type
为String
。它还具有名为 PDFData
的列,类型为 PFFile
。我希望这样,当用户单击 TableViewCell
时,它会转到新的 View Controller
并在 WebView< 中显示
.PDF
/
目前这些fileNames
位于TableView
中。我有一个使用 WebView
转到 View Controller
的 Segue。它将 TableViewCell
中的 fileName
名称作为全局变量
传递。
我的查询
用于解析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
加载 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
}
我有将所选单元格
fileName
传递给全局变量
的代码,如下所示:
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
中>?我不知道如何将所有这些都放入 URL
中以与 WebView
一起使用。我看了here并尝试用我的实现这一点,但没有成功。谢谢。
最佳答案
不要只用
保存文件名self.fileName.append(object["fileName"] as! String)
保存PFObject
的整个列表。这些对象将包含文件名(可用于 TableView )和 PFFile 引用(可在向下钻取时使用)。另外,你似乎没有,但你不应该通过全局。看起来您只是在 segue 中传递文件名。
您应该传递整个PFObject
,而不是传递文件名。然后,在目标 View Controller 中,您可以提取 PFFile
引用及其包含的 URL。
关于ios - 使用 Xcode7 和 Swift 2 在 WebView 中查看 Parse PFFile PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34792696/