ios - 在单元格上单击显示特定登录 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)
}
任何人都可以帮我为发布工作的各个用户获取图像吗?
解决方案
只需使用像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)
}
}
}
推荐阅读
- python-3.x - Tensorflow:了解 tf.contrib.seq2seq.BasicDecoder
- javascript - getJSON 二级拼图
- node.js - 节点 dbus 网络管理器 IPV6 地址属性绑定
- fiware - 我可以创建一个仅通知那些已更改的上下文属性的订阅吗?
- ios - Swift - libc++abi.dylib:以 NSException (lldb) 类型的未捕获异常终止
- c# - .Net core Hosted Services 保证完成
- c# - 如何使用 EP Plus 将选项/值作为下拉列表添加到我的 Excel 表格的标题中?
- python - 正则表达式检查字符串是否在python中至少有一个到三个单词和一个以上的标签
- mongodb - 如何仅为内部对象而不是整个集合创建唯一索引?
- python - 如何对协程进行速率限制并在限制后重新调用协程?