在单元格上单击显示特定登录 ID 的图像 [英] On cell click display image of particular logged in 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做{如果错误 == 零{self.jobArray = 尝试 JSONDecoder().decode([JobData].self, from: data!)用于 self.jobArray 中的 mainJobArr{DispatchQueue.main.async {self.jobPostTblView.reloadData()}}打印(作业数据****\(self.jobArray)")}}抓住{//打印("我的数据=\(self.mainCellData)")打印(获取JSON数据时出错\(错误)")}}.恢复()}
numberOfRowsInSection
func tableView(_ tableView: UITableView, numberOfRowsInSection 部分: Int) ->整数{返回 jobFilteredArray.count}
cellForRowAtIndexPath 方法
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) ->UITableViewCell {let cell = Bundle.main.loadNibNamed("JobTableViewCell", owner: self, options: nil)?.first as!作业表视图单元格让数据 = jobArray[indexPath.row]cell.jobTitle.text = data.job_desigcell.expDetails.text = data.job_exp_tocell.locationDetails.text = data.job_locationcell.dateDetails.text = data.job_skillscell.companyName.text = companyArray.first { $0.company_id == data.company_id }?.company_name返回单元格}
didSelectRowAtIndexPath
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath){让 selectedCell:UITableViewCell = tableView.cellForRow(at: indexPath)!selectedCell.contentView.backgroundColor = UIColor.white让行 = indexPath.row打印(行=\(行)")让 jobDetail = WorkerJobDetailsViewController(nibName: "WorkerJobDetailsViewController", bundle: nil)让 jdata = jobFilteredArray[indexPath.row]jobDetail.gender = jobArray[indexPath.row].job_emp_genderjobDetail.location = jobArray[indexPath.row].job_locationjobDetail.companyName = (companyArray.first { $0.company_id == jdata.company_id }?.company_name)!jobDetail.profile = jobImgPathjobImgPath = (companyArray.first { $0.company_id == jdata.company_id }?.company_logo)!jobDetail.skills = jobArray[indexPath.row].job_skillsjobDetail.descriptionValue = jobArray[indexPath.row].job_descjobDetail.jobDesignation = jobArray[indexPath.row].job_desigself.present(jobDetail,动画:true,完成:nil)}
任何人都可以帮我获取已发布职位的各个用户的图片吗?
只需使用像 SDWebImage 并使用您正在映射的 url 获取链接,您将面临的问题是该链接是本地 ip,它无法从远程网络工作,但如果将来 json 中的链接发生更改,您会没事的
没有 pod,你可以做到这一点
func getDataFromUrl(url: URL, completion: @escaping (Data?, URLResponse?, Error?) -> ()) {URLSession.shared.dataTask(with: url) { data, response, error in完成(数据,响应,错误)}.恢复()}func 下载图片(网址:网址){打印(下载开始")getDataFromUrl(url: url) { 数据,响应,错误守卫让数据=数据,错误==零其他{返回}打印(响应?.建议文件名??url.lastPathComponent)print("下载完成")DispatchQueue.main.async() {self.imageView.image = UIImage(data: data)}}}
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).
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??
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)
}
}
}
这篇关于在单元格上单击显示特定登录 ID 的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!