Ios 从URL加载图像的工作不一致
我将Ios 从URL加载图像的工作不一致,ios,swift,url,uiimage,load,Ios,Swift,Url,Uiimage,Load,我将URL存储为组织中的字符串。这些URL用于获取每个组织的徽标并将其显示在tableview中。以下是我用于执行此操作的代码: override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "orgcell", for
URL
存储为组织中的字符串。这些URL用于获取每个组织的徽标并将其显示在tableview中。以下是我用于执行此操作的代码:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "orgcell", for: indexPath) as! OrgCell
cell.orgAcro.text = filteredOrgs[indexPath.row].acronym
cell.topTag.text = filteredOrgs[indexPath.row].tags[0].title
let data = try? Data(contentsOf: filteredOrgs[indexPath.row].url)
if (data == nil) {
cell.orgImg.image = UIImage()
} else {
cell.orgImg.image = UIImage(data: data!)
}
return cell
}
这是唯一的工作网址是这一个
它对这个不起作用
这与我加载它们的顺序无关,我已经尝试过将其打开。有什么想法吗?区别在于一个是HTTPS,另一个不是。您需要编辑您的信息列表,将应用程序传输安全密钥和网站域添加到例外列表或允许任意下载。顺便说一句,你应该看看这个UIImageView扩展,我将先发制人地告诉你如何在背景线程上引导图像。如果不这样做,您的UI将变得滞后。请使用AlamofireImage或SDWebImage进行此操作,否则您将有严重的口吃,因为您的数据调用正在阻塞主线程。