我试图在UIImageView中显示图像。我使用SDWebImage库来显示图像。请注意,我也尝试过常规方法。当我直接提供URL时,它运行良好。但是当它从导航推送的上一个类传递时,它实际上是正确的,当我打印它,但图像没有显示。
这是我的代码
// ImageViewer类ViewDidLoad()方法
print(imageUrl)
imageView.sd_setImage(with: URL(string: String(describing: imageUrl)), placeholderImage: UIImage(named: "logo"))
//从这个班级我传递了这个URL
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "ImageViewer") as! ImageViewer
print(self.url)
nextViewController.imageUrl = String(describing: self.url)
self.navigationController?.pushViewController(nextViewController, animated: true)
我也试过加载Video和pdf,两种情况都是如此。所以问题一定不是因为我如何显示图片。
请在这件事上给予我帮助
我得到了答案。这是一个简单的愚蠢错误。当我从后端获取URL时,我在字符串的开头和结尾处有额外的双引号字符。当我在下一个类中打印字符串时,我认为字符是默认的字符串字符。但后来我意识到自己的错误。
所以我用空字符串替换了不必要的字符串,现在它运行良好。
let myString = urlString.replacingOccurrences(of: "\"", with: "")
我希望有一天我的回答会对某人有所帮助。谢谢。