我试图在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,在两种情况下都一样。所以问题一定不是因为我如何显示图片。
请帮助我
答案 0 :(得分:0)
我得到了答案。这是一个简单的愚蠢错误。当我从后端获取URL时,在字符串的开头和结尾都有多余的双引号字符。当我在下一堂课中打印字符串时,我认为这些字符是默认的字符串字符。但是后来我意识到自己的错误。
所以我用空字符串替换了不必要的字符串,现在它运行良好。
let myString = urlString.replacingOccurrences(of: "\"", with: "")
我希望有一天我的回答能对某人有所帮助。谢谢。