![](/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.