如何从json获取图像和pdf文件并在tableviewcell swift 3中显示

del*_*ami 7 json uitableview uiimageview swift3

大家好,因为我是一个新手所以不知道如何从API获取图像和pdf文件以及如何在tableviewcell中显示,以便用户可以看到图像和pdf文件以及从那里下载它.我尝试了一些图像代码,但它不工作,对pdf没有一个想法.请帮忙.

image的代码:我已声明了如下图像数组:

var announimage : Array = [UIImage]()
Run Code Online (Sandbox Code Playgroud)

以下是我的JSON数据的格式.

{
 "Download_Details": [
 {
"school_id": 1,
"class_id": "Pre - KG ",
"section": "A ",
"file_name": "427a3be0155b49db999cffb51f078f9c_431875732.pdf",
"title": "TeQ",
"message": "Hello Users",
"date": null
},
{
"school_id": 1,
"class_id": "Pre - KG ",
"section": "A ",
"file_name": "dce5ab53f45f4ec5b52894bc6286ed35_1376021.jpg",
"title": "Welcome",
"message": "Welcomes you.",
"date": null
},
{
 "school_id": 1,
 "class_id": "Pre - KG ",
 "section": "A ",
 "file_name": "9d3ff19bd54e48a087947227ee36c68c_13417773.png",
 "title": "TEST",
"message": "TEST",
"date": null
}
],
}
Run Code Online (Sandbox Code Playgroud)

以下是我尝试过的代码:

let responseString = try! JSONSerialization.jsonObject(with: data!, options: .allowFragments) as? NSDictionary

let downarray = responseString?.value(forKey: "Download_Details") as? NSArray

for down in downarray!
{
    let dowdict = down as? NSDictionary

    let dmsgname = dowdict?.value(forKey: "message")

    self.announmessage.append(dmsgname as! String)

   let downimage = dowdict?.value(forKey: "file_name")

   self.announimage.append(downimage as! UIImage)


}

DispatchQueue.main.async                                    
{
    self.annountable.reloadData()
}
Run Code Online (Sandbox Code Playgroud)

UITableView数据源:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let cell2 = tableView.dequeueReusableCell(withIdentifier: "cell1", for: indexPath) as! AnnounceCellTableViewCell
    cell2.announlabel.text = announmessage[indexPath.row]
    cell2.announdate.text = announcedates[indexPath.row]
    let image :UIImage = UIImage(data:announimage[indexPath.row] as! Data)!
    cell2.dataimage.image = image       
     return cell2

}    
Run Code Online (Sandbox Code Playgroud)

Buc*_*ket 1

在行的单元格上尝试以下代码

let image : UIImage = UIImage(data: filteredAry[indexPath.row] as! Data)

cell2.dataimage.image = image
Run Code Online (Sandbox Code Playgroud)