Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用swift为imageview变量使用sdwebimage下载图像_Swift_Download_Imageview_Sdwebimage_Programmatically - Fatal编程技术网

使用swift为imageview变量使用sdwebimage下载图像

使用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") &

我正在使用SDWebImage从API获取图像。我没有为
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)
也发布了下载的图像代码