【发布时间】:2016-01-14 15:00:26
【问题描述】:
我正在使用Xcode7 和Swift2 处理一个iOS 项目。我有一个PDF 正在保存到Parse。它正在保存到名为IncomingRecipe 的Parse Class。在这个Class 是一个FileName 列,type 是一个String。它还有一个名为PDFData 的列,类型为PFFile。我想要它,所以当用户点击TableViewCell 时,它会转到新的View Controller 并在WebView 中显示PDF。
目前这些fileNames 位于TableView 中。我有一个转到View Controller 和WebView 的segue。它将fileName 的名称从TableViewCell 传递为Global variable。
我的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 将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 中?我不知道如何将所有这些放入URL 以与WebView 一起使用。我查看了here 并尝试用我的方法实现这一点,但没有成功。谢谢。
【问题讨论】:
标签: ios swift parse-platform uiwebview xcode7