首页 > 解决方案 > 在单元格上单击显示特定登录 ID 的图像

问题描述

在比较包含用户详细信息的表的 ID 之后,我需要在下一个视图控制器中打印图像 在比较 ID 后我成功获取了名称,但是如果用户发布了任何内容,则相应的图像无法获取,那么我正在获取特定的名称现在发布的工作我想要的是来自各个用户的图像(用户在注册时上传的图像),(它标识发布的工作是通过哪个用户发布的)。

邮递员的工作回应 邮递员的公司回应

下面是我的代码:

func getJOBData()
    {
        let jobUrl = URL(string: "http://172.16.1.22/Get-Job-API/get-jobs/")
        URLSession.shared.dataTask(with: jobUrl!) { (data, response, error) in

            do
            {
                if error == nil
                {
                    self.jobArray = try JSONDecoder().decode([JobData].self, from: data!)

                    for mainJobArr in self.jobArray
                    {
                        DispatchQueue.main.async {
                            self.jobPostTblView.reloadData()
                        }
                    }
                    print("Job Data****\(self.jobArray)")
                }
            }

            catch
            {
                //                print("my data=\(self.mainCellData)")
                print("Error in get JSON Data\(error)")
            }
            }.resume()
    }

numberOfRowsInSection

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

            return jobFilteredArray.count
        }

cellForRowAtIndexPath 方法

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = Bundle.main.loadNibNamed("JobTableViewCell", owner: self, options: nil)?.first as! JobTableViewCell

            let data = jobArray[indexPath.row]
            cell.jobTitle.text = data.job_desig
            cell.expDetails.text = data.job_exp_to
            cell.locationDetails.text = data.job_location
            cell.dateDetails.text = data.job_skills
            cell.companyName.text = companyArray.first { $0.company_id == data.company_id }?.company_name

return cell

        }

didSelectRowAtIndexPath

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath){
                let selectedCell:UITableViewCell = tableView.cellForRow(at: indexPath)!
                selectedCell.contentView.backgroundColor = UIColor.white

                let rows = indexPath.row
                print("Rows=\(rows)")
                let jobDetail = WorkerJobDetailsViewController(nibName: "WorkerJobDetailsViewController", bundle: nil)

                let jdata = jobFilteredArray[indexPath.row]
                jobDetail.gender = jobArray[indexPath.row].job_emp_gender
                jobDetail.location = jobArray[indexPath.row].job_location
                jobDetail.companyName = (companyArray.first { $0.company_id == jdata.company_id }?.company_name)!

                jobDetail.profile = jobImgPath
                jobImgPath = (companyArray.first { $0.company_id == jdata.company_id }?.company_logo)!

                jobDetail.skills = jobArray[indexPath.row].job_skills
                jobDetail.descriptionValue = jobArray[indexPath.row].job_desc
                jobDetail.jobDesignation = jobArray[indexPath.row].job_desig

                self.present(jobDetail, animated: true, completion: nil)
            }

任何人都可以帮我为发布工作的各个用户获取图像吗?

标签: iosswift3swift4

解决方案


只需使用像SDWebImage这样的 pod并使用您正在映射的 url 获取链接,您将面临的问题是该链接是本地 ip,并且它不能从远程网络工作,但是如果链接在 json 中发生更改未来你会没事的

没有 pod 你可以这样做

    func getDataFromUrl(url: URL, completion: @escaping (Data?, URLResponse?, Error?) -> ()) {
    URLSession.shared.dataTask(with: url) { data, response, error in
        completion(data, response, error)
    }.resume()
    }

    func downloadImage(url: URL) {
    print("Download Started")
    getDataFromUrl(url: url) { data, response, error in
        guard let data = data, error == nil else { return }
        print(response?.suggestedFilename ?? url.lastPathComponent)
        print("Download Finished")
        DispatchQueue.main.async() {
            self.imageView.image = UIImage(data: data)
        }
      }
   }

推荐阅读