0
나는 이미지를 보여 주며 뷰가로드 될 때마다 이미지를 다시 다운로드하는 tableView에서 작업하고 있습니다. 이미지를 한 번만 다운로드하도록 캐시하는 방법이 있습니까?사용자가 앱을 열 때마다 이미지를 다시 다운로드하지 않을 방법이 있습니까?
나는 이미지를 보여 주며 뷰가로드 될 때마다 이미지를 다시 다운로드하는 tableView에서 작업하고 있습니다. 이미지를 한 번만 다운로드하도록 캐시하는 방법이 있습니까?사용자가 앱을 열 때마다 이미지를 다시 다운로드하지 않을 방법이 있습니까?
당신이 할 수있는 (이미지를 캐시) : 당신의 tableViewDelegate에서
셀에
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if let row = tableView.dequeueReusableCellWithIdentifier("MyCell") as? MyCell{
//Get the item
let item = items[indexPath.row]
//You need to cancel previous requests and reset the image to avoid render errors caused by the reusable row
//here you should also cancel any previous requests made to avoid downloading an image that the user won't see because he scrolled
cell.img.image = nil
//Search for the image in the cache
var img:UIImage?
img = myCache.objectForKey(item.image_url) as? UIImage
row.configureCell(item: item,img:img)
return row
}else{
return MyCell()
}
}
그리고 마지막으로 rowAtIndexPath에 그런 다음 캐시 개체
var myCache = NSCache()
을 만들
func configureCell(item:Item,image:UIImage?){
self.item = item
if image != nil{
//The image exist so you assign it to your UIImageView
img.image = image
}else{
//Create the request to download the image
}
}
whi ch 언어를 사용하고 있습니까? – Ymmanuel
나는 신속하게 사용하고있다. – gooberboobbutt
NSCache를 사용하여 이미지 요청을하고 재 다운로드하지 않거나 Firebase SDK 기능을 의미합니까? – Ymmanuel