gpt4 book ai didi

ios - 为什么我不能使用 SDWebImage 下载 png 格式的文件?

转载 作者:行者123 更新时间:2023-11-28 09:50:30 27 4
gpt4 key购买 nike

我正在尝试调试我的代码,我发现我的图像没有出现的问题是因为我无法使用 SDWebImage 下载我的 png 格式文件。

如果格式是jpg就可以正常工作。这是 TableView Controller 中的完整简化代码。

class ViewController: UIViewController, UITableViewDataSource {
@IBOutlet weak var tableView: UITableView!

var imageURLs = [String]()

override func viewDidLoad() {
super.viewDidLoad()
tableView.dataSource = self
imageURLs = ["https://app10.pakubuwono6.com/hris/images/notification/Logo Small.png", "https://app10.pakubuwono6.com/hris/images/notification/Logo Small.png", "https://app10.pakubuwono6.com/hris/images/notification/Logo Small.png", "https://app10.pakubuwono6.com/hris/images/notification/Logo Small.png"]
tableView.reloadData()
}

func numberOfSections(in tableView: UITableView) -> Int {
return 1
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return imageURLs.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cellImage") as! CellImage
cell.imageExample.sd_setImage(with: URL(string: imageURLs[indexPath.row]), placeholderImage: UIImage(named: "placeholder"), options: [.continueInBackground, .progressiveDownload])
return cell
}
}

我正在使用下面的代码行来下载图像,我在这个 View Controller 的 TableView 单元格中设置了图像

cell.imageExample.sd_setImage(with: URL(string: imageURLs[indexPath.row]), placeholderImage: UIImage(named: "placeholder"), options: [.continueInBackground, .progressiveDownload])

这里出了什么问题?

只出现占位图片 enter image description here

最佳答案

您的图片网址包含空格试试这段代码

if let url = imageURLs[indexPath.row].addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed){
cell.imageExample.sd_setImage(with: URL(string: url), placeholderImage: UIImage(named: "placeholder"), options: [.continueInBackground, .progressiveDownload])

}

关于ios - 为什么我不能使用 SDWebImage 下载 png 格式的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49299280/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com