title: UICollectionView cellForItemAtIndexPath called over and over again on scrolling
body: <p>I have a <code>UICollectionView</code> in which each cell is populated asynchronously from Flickr. </p>
  
  <p>In my scene I want 21 cells, my code produces this just fine. However, my code is calling Flickr again and again even after all 21 cells are populated in the <code>cellForItemAtIndexPath</code> method. I looks at the Apple docs and I didn't see anywhere that states that <code>cellForItemAtIndexPath</code> should be continuously called upon scrolling. </p>
  
  <p>I want each cell to be populated just once and then once completed <code>cellForItemAtIndexPath</code> shouldn't be called again. </p>
  
  <p>Here is my code : </p>
  
  <pre><code>import UIKit
  import MapKit
  import CoreData
  
  class ImagesCollectionViewController : UIViewController, UICollectionViewDataSource, UICollectionViewDelegate{
  
      @IBOutlet weak var mapView: MKMapView!
  
      @IBOutlet weak var collectionView: UICollectionView!
      var mapLat : Double!
      var mapLong : Double!
      let flickrApi = Flickr()
      var imageURLSet = [String]()
  
      override func viewDidLoad() {
  
          // set the location and zoom of the minimap
          let clLocation = CLLocationCoordinate2D(latitude: mapLat, longitude: mapLong)
          let span = MKCoordinateSpan(latitudeDelta: 2, longitudeDelta: 2)
  
          mapView.setRegion(MKCoordinateRegion(center: clLocation, span: span), animated: false)
          mapView.scrollEnabled = false
  
          getImages()
      }
  
      func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
          return imageURLSet.count
      }
  
      func numberOfSectionsInCollectionView(collectionView: UICollectionView) -&gt; Int {
          return 1
      }
  
      func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -&gt; UICollectionViewCell {
          print("test") // &lt;--- this prints over and over again on scrolling
          let cell = collectionView.dequeueReusableCellWithReuseIdentifier("ImageCell", forIndexPath: indexPath) as! FlickrImageCellViewController
          let queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
          dispatch_async(queue) { () -&gt; Void in
              let url = NSURL(string: self.imageURLSet[indexPath.row])
              let data = NSData(contentsOfURL: url!)
              let img = UIImage(data: data!)
  
              dispatch_async(dispatch_get_main_queue(), {
                   cell.imageView.image = img
              })
  
  
          }
  
          // This is where the cells are being populated
  
  
          return cell
      }
  
      //Get images from the flickr API and store in array
  
      func getImages(){
  
          let parameters : [String : AnyObject] = ["method": Flickr.Consts.GEO_METHOD, "format" : Flickr.Consts.FORMAT, "api_key": Flickr.Consts.API_KEY, "lat" : mapLat, "long" : mapLong, "nojsoncallback" : "1", "per_page" : "21", "extras" : "url_m"]
  
          flickrApi.performGetRequest(parameters) { (data, error) in
  
  
              for record in data as! [AnyObject]{
                  if(record["url_m"] != nil){
                      print("record")
                      print(record["url_m"] as! String)
                      print("end record")
                      self.imageURLSet.append(record["url_m"] as! String)
  
                  }
              }
          }
      }
  
      override func viewDidAppear(animated: Bool) {
  
          self.collectionView.reloadData()
      }
  }
  </code></pre>