使用swift为imageview变量使用sdwebimage下载图像
我正在使用SDWebImage从API获取图像。我没有为使用swift为imageview变量使用sdwebimage下载图像,swift,download,imageview,sdwebimage,programmatically,Swift,Download,Imageview,Sdwebimage,Programmatically,我正在使用SDWebImage从API获取图像。我没有为imageview创建IBOutlet,而是通过编程方式创建了imageview,并使用downloadImage(带url:url)函数获取webimage。每次单击图像时,必须用新图像替换此imageview。问题是,当我单击新图像时,该新图像与现有图像重叠。它不会替换旧图像。我的问题是,downloadimage函数是否总是这样工作,或者我的工作方式是否存在任何问题 if (vtype[i] == "OtherView") &
imageview
创建IBOutlet
,而是通过编程方式创建了imageview
,并使用downloadImage(带url:url)
函数获取webimage
。每次单击图像时,必须用新图像替换此imageview
。问题是,当我单击新图像时,该新图像与现有图像重叠。它不会替换旧图像。我的问题是,downloadimage
函数是否总是这样工作,或者我的工作方式是否存在任何问题
if (vtype[i] == "OtherView") && (cattypelink == "Image")
{
print("i is \(i)")
imagestrng = demoarray[i]
self.imgtag = i
self.tag = self.imgtag
print("imagestring is sswqqwqew \(imagestrng)")
let actualURL = URL(string: imagestrng)
self.downloadImage(with: actualURL!)
}
func downloadImage(with url:URL) {
print("inside download image")
SDWebImageManager.shared().downloadImage(with: url, options: SDWebImageOptions(rawValue: 0), progress: nil) { (image, _, _, _, _) in
if let _ = image {
print("image downloaded")
if self.tag == self.imgtag
{
var finalimage: UIImage = image!
print("finalimage is \(finalimage)")
self.othersimg = UIImageView(frame: self.oview.frame)
self.othersimg?.image = nil
self.othersimg?.image = finalimage
self.oview = UIView(frame: CGRect(x:0,y:0,width:self.sigeImg.width,height:self.sigeImg.height))
self.mainview.addSubview(self.oview)
self.oview.addSubview(self.othersimg!)
self.othersimg?.tag = self.imgtag
print("othersimg is \(self.othersimg?.tag)")
}
else
{
print("nothing")
}
}
else {
print("not downloaded '")
// Try to download again (optional)
self.downloadImage(with: url)
}
}
}
请发布更多代码,以便我们了解您的程序中正在发生的情况。尤其是函数
downloadImage(with:URL)
也发布了下载的图像代码