Ios 使用Xcode7和Swift 2在WebView中查看解析PDF文件
我有一个Ios 使用Xcode7和Swift 2在WebView中查看解析PDF文件,ios,swift,parse-platform,uiwebview,xcode7,Ios,Swift,Parse Platform,Uiwebview,Xcode7,我有一个iOS项目,我正在使用Xcode7和Swift2。我有一个PDF正在保存到Parse。它正在保存到一个名为IncomingRecipe的Parse类中。在这个类中是一个文件名列,其中类型为字符串。它还有一个名为PDFData的列,类型为PFFile。我希望这样,当用户单击TableViewCell时,它会切换到一个新的视图控制器,并在WebView中显示PDF 目前,这些文件名位于表格视图中。我有一个序列,通过WebView进入视图控制器。它将表格视图单元格中的文件名作为全局变量传递 我
iOS
项目,我正在使用Xcode7
和Swift2
。我有一个PDF
正在保存到Parse
。它正在保存到一个名为IncomingRecipe
的Parse
类中。在这个类中
是一个文件名
列,其中类型
为字符串
。它还有一个名为PDFData
的列,类型为PFFile
。我希望这样,当用户单击TableViewCell
时,它会切换到一个新的视图控制器
,并在WebView
中显示PDF
目前,这些文件名
位于表格视图中
。我有一个序列,通过WebView
进入视图控制器。它将表格视图单元格中的文件名
作为全局变量
传递
我的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
将文件名加载为:
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
}
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)")
}
}
}
我有将选定的单元格
文件名
传递给全局变量的代码,如下所示:
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
}
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
,并将其显示在另一个视图控制器上的WebView
中?我不知道如何将所有这些内容都放到URL
中,以便与WebView
一起使用。我看了看,试图用我的实现,但没有成功。谢谢。不要只保存文件名
self.fileName.append(object["fileName"] as! String)
保存PFObject
s的整个列表。这些对象将包含文件名(可用于表视图)和PFFile
引用(可用于向下钻取)。而且,你看起来没有,但你不应该路过。看起来您正在传递序列中的文件名
您应该传递整个PFObject
,而不是传递文件名。然后,在destination view controller中,您可以提取PFFile
引用及其包含的URL。我是新手。我如何通过整个对象?我是否创建了一个具有PFObject类型的全局变量,然后将其设置为TableView控制器中的当前PFObject,然后再切换到WebView?我按照您的建议保存了整个列表。请查看我的编辑。从不使用全局变量!与名称完全相同,只需更改变量类型,只需保存PFObject数组,无需单独中断,只需稍加调整即可。谢谢你给了我这个想法。