Git Product home page Git Product logo

image-cache-example's Introduction

image-cache-example

이미지를 가져올 때 캐시를 이용하는 방법을 연습

image-cache-example's People

Contributors

woin2ee avatar

Watchers

 avatar

image-cache-example's Issues

테이블뷰를 빠르게 스크롤 했을때 이미지가 잘못 세팅되었다가 다시 정상적으로 세팅되는 문제

원인

  • bind() 함수는 Cell 의 contents 를 세팅하는 함수인데 이미지는 비동기 호출을 통해 가져왔다.
  • tableView(_:cellForRowAt:) 에서 Reusable Cell 을 생성하여 Cell 이 화면에 나타날때마다 Cell.bind() 함수를 호출했다.
  • Reusable Cell 을 사용하니까 Cell 객체의 개수는 정해져있는데 bind() 함수를 계속 호출하니까 Cell 에 이미지를 세팅하는 로직이 하나의 Cell 객체에서 중복 실행되어 먼저 가져온 이미지 부터 세팅되는 문제였다.

해결 방안

1. Cell 의 prepareForReuse() 함수에서 비동기 이미지 요청을 취소하여 이미지가 여러번 세팅되지 않게 하는 방법

사용자가 스크롤을 빠르게 내리다가 마음에 드는 Item 이 있어서 다시 스크롤을 올릴 때, 이미지를 다시 가져와야 하므로 사용자를 기다리게 할 수도 있다.

2. 이미지를 요청했던 Cell 의 IndexPath 를 기억하여 이미지를 가져온 후, 기억했던 IndexPath 로 다시 Cell 을 불러내 이미지를 세팅 하는 방법

모든 Cell 에 대한 이미지를 가져오기 때문에 네트워크적으로 부하가 걸릴 수 있다.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.