On cell click display image of particular logged i

2019-09-02 17:15发布

I need to print image in my next view controller after comparing ID of a table containing user details after comparing the ID I am successfully getting the name but the respective image is unable to fetch if the user has posted anything then I am getting name for particular posted job now what I want is image of from respective user (that image which user uploaded while registration), (which identifies the posted job is posted via which user).

Job Response from Postman Company Response from Postman

Below is my code:

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 Method

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)
            }

Can anyone please help me to fetch images for respective user of posted job??

1条回答
Evening l夕情丶
2楼-- · 2019-09-02 17:59

just use a pod like SDWebImage and fetch the link with the url that you are mapping the problem that you will face is that the link is a local ip and it will not work from a remote network but if the link changes at the json in the future you will be fine

Without pod you can do this

    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)
        }
      }
   }
查看更多
登录 后发表回答