![](/img/trans.png)
[英]Loading local images from documents directory to tableview using SDWebImage
[英]Issues loading images using SDWebImage
我正在使用SDWebImage库加载用户个人资料的图像。 奇怪的是,当我打开一个包含5张照片的配置文件时,滚动视图中仅显示最后一张图像(您可以滚动浏览全宽配置文件图片)。 但是,如果我关闭视图并重新打开,则所有图像都在那里并且看起来很完美。 关于发生了什么的任何想法? 这是代码:
func getPhotos(user:PFUser, forKey:NSMutableArray) {
var p = 0
for f in forKey {
if let pic = user.objectForKey(f as! String) as? PFFile {
var width = Int(phonewidth)
photoscroll.contentSize = CGSize(width: CGFloat((p + 1) * width), height: phonewidth)
pageControl.numberOfPages = p + 1
var position = CGFloat(p*width)
var imgview = UIImageView(frame: CGRectMake(position, 0, phonewidth, phonewidth))
imgview.sd_setImageWithURL(NSURL(string: pic.url), completed: {(image: UIImage!, error: NSError!, cacheType: SDImageCacheType, imageURL: NSURL!) in
imgview.image = image
self.photoscroll.addSubview(imgview)
self.userpics.append(image)
p++
println("Added: \(f), URL: \(pic.url)" )
})
}
}
}
您增加p的时间太晚了,完成块不会立即运行,因此您的循环每次运行时p的值都将相同,并且图像视图将全部堆叠在一起。
将p++
放在块外。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.