ios - When pulling images from a Firebase storage the images don’t load until I interact with the tableView by scrolling... SWIFT 3 -


i’m running problems twitter/instagram news feed…

when pulling images firebase storage images don’t load until interact tableview scrolling... more scroll, more can appear. randomly displays wrong post image until scroll more , images load , settle in correct places.

it doesn’t make sense… logic correct , using cachedimages when loading image urls database. i’ve watched lot video tutorials , use similar approaches i’ve used none of them have buggy problems ike do.

any ideas on problem might be?

code:

var imagecache = [string: uiimage]()    var lasturlusedtoloadimage: string?

// loading user image  urls  extension uiimageview {            func loadimage(urlstring: string) {                    lasturlusedtoloadimage = urlstring                    if let cachedimage = imagecache[urlstring] {              self.image = cachedimage              return          }                    guard let url = url(string: urlstring) else { return }                    urlsession.shared.datatask(with: url) { (data, response, err) in              if let err = err {                  print("failed fetch post image:", err)                  return              }                            if url.absolutestring != lasturlusedtoloadimage {                  return              }                            guard let imagedata = data else { return }                            let photoimage = uiimage(data: imagedata)                            imagecache[url.absolutestring] = photoimage                            dispatchqueue.main.async {                  self.image = photoimage              }                            }.resume()      }  }

you should use

tableview.reloaddata() 

when image downloaded.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -