title: UICollectionView is not scrolling smooth on reload data
body: <p>In my UICollecitonView, I am appending data from API using</p>
  
  <p>self.DataTableCollectionView.reloadData()</p>
  
  <p>But as data in my collection gets increasing, its scrolling becomes rough and after loading some pages, it becomes very hard to scroll up or down. It is getting stuck.</p>
  
  <p>Eventually when I tried to load 1000 rows at a time scrolling works smooth but when I try to paginate and load 50 rows at a time using API, then it becomes hard to scroll.</p>
  
  <p>What would be the problem can any one help me out?</p>
  
  <p>I am not able to figure out what iss wrong? Is self.DataTableCollectionView.reloadData() reponsible for this?</p>
  
  <p>Here is the code to load data on scroll :</p>
  
  <pre><code>func scrollViewDidScroll(scrollView: UIScrollView) {
  
       let offsetY = scrollView.contentOffset.y
       let contentHeight = scrollView.contentSize.height
  
       if(offsetY &gt; (contentHeight - scrollView.frame.size.height)){              
  
           let seconds = 3.0
           let delay = seconds * Double(NSEC_PER_SEC)
           let dispatchTime = dispatch_time(DISPATCH_TIME_NOW, Int64(delay))
  
           self.loadMoreData()
           dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), {
               self.DataTableCollectionView.reloadData()
  
           })                
        }        
  
  }
  </code></pre>
  
  <p>==========</p>
  
  <p>I am reusing the cells as</p>
  
  <pre><code>self.DataTableCollectionView .registerNib(UINib(nibName: "DCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: dCellIdentifier)
  self.DataTableCollectionView .registerNib(UINib(nibName: "CCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: cCellIdentifier) 
  </code></pre>
  
  <p>and for reusing:</p>
  
  <pre><code>func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -&gt; UICollectionViewCell {
  
  let dCell : DCollectionViewCell = collectionView .dequeueReusableCellWithReuseIdentifier(dCellIdentifier, forIndexPath: indexPath) as! DCollectionViewCell
  
  let cCell : ContentCollectionViewCell = collectionView .dequeueReusableCellWithReuseIdentifier(cCellIdentifier, forIndexPath: indexPath) as! CCollectionViewCell       
  }
  </code></pre>
  
  <p>=========</p>
  
  <p>Adding more specific code:</p>
  
  <p>Now I have Updated my scrolling function,</p>
  
  <pre><code>func scrollViewDidScroll(scrollView: UIScrollView) {
      let offsetY = scrollView.contentOffset.y
      let contentHeight = scrollView.contentSize.height
      if(offsetY &gt; (contentHeight - scrollView.frame.size.height)){
         var returnTableData = NSMutableArray()
  
         self.InspectPageId = self.InspectPageId+1
         self.dataSource.populateData(PageId:self.InspectPageId)
         returnTableData = self.dataSource.DTableDataArray
  
         if(returnTableData.count&gt;0){
            for i in 0..&lt;returnTableData.count {
               self.TableDataArray.addObject(returnTableData[i])
            }
         }
         self.NumberOfRows = self.TableDataArray.count
  
         dispatch_async(dispatch_get_main_queue(),{
            self.DataTableCollectionView.reloadData()
         })
     }
  }
  </code></pre>
  
  <p>Following is the code for creating collection view manually:</p>
  
  <pre><code>if indexPath.row == 0 {
  //Here Header Cell is creating
                  let dateCell : DateCollectionViewCell = collectionView .dequeueReusableCellWithReuseIdentifier(dateCellIdentifier, forIndexPath: indexPath) as! DateCollectionViewCell
                  dateCell.dateLabel.font = UIFont(name:"HelveticaNeue", size: 12)
                  dateCell.dateLabel.textColor = UIColor.blackColor()
                  dateCell.dateLabel.textAlignment = .Left
                  dateCell.dateLabel.text = UMIDDataArray[rowIndex-1] as? String
                  dateCell.backgroundColor = UIColor.whiteColor()
                  dateCell.layer.shouldRasterize = true
                  dateCell.layer.rasterizationScale = UIScreen.mainScreen().scale
                  return dateCell
              } else {
  //Here Data Cell is Creating
                  let contentCell : ContentCollectionViewCell = collectionView .dequeueReusableCellWithReuseIdentifier(contentCellIdentifier, forIndexPath: indexPath) as! ContentCollectionViewCell
                  contentCell.contentLabel.font = UIFont(name:"HelveticaNeue", size: 12)
                  contentCell.contentLabel.textColor = UIColor.blackColor()
                  contentCell.contentLabel.textAlignment = .Left
                  contentCell.bottomBorder.hidden  = false
                  contentCell.layer.shouldRasterize = true
                  contentCell.layer.rasterizationScale = UIScreen.mainScreen().scale
  
                  let LensData:NSArray =  TableDataArray[rowIndex-1] as! NSArray
                  let ColumnValue = LensData[colIndex-1] as? String
                  contentCell.contentLabel.text = ColumnValue
                  contentCell.backgroundColor = UIColor.whiteColor()
  
                  return contentCell
              }
  
  Following is the code which is use to take data from API:
  
  //function of DataSource Class.
  func populateData(PageId:Int){
  var returnData = NSMutableArray()
  let OtherColobjects = NSMutableArray()
  
  let Urlpath = SetApiUrl()
  let url: NSURL = NSURL(string: Urlpath)!
  let urlRequest = NSURLRequest(URL: url)
  
  let config = NSURLSessionConfiguration.defaultSessionConfiguration()
  let session = NSURLSession(configuration: config)
  
  let semaphore = dispatch_semaphore_create(0)
  let task = session.dataTaskWithRequest(urlRequest) {
  (data, response, error) in
  
  guard error == nil else {
  return
  }
  
  guard let responseData = data else {
  return
  }
  
  do {
  guard let Data = try NSJSONSerialization.JSONObjectWithData(responseData, options: []) as? [String: AnyObject] else {
  return
  }
  
  for anItem in Data["result"]!["DATA"] as! [Dictionary&lt;String, AnyObject&gt;] {
  let d1 = self.checkForNull(anItem["data1"]!)
  let d2 = self.checkForNull(anItem["data2"]!)
  let d3 = self.checkForNull(anItem["data3"]!)
  let d4 = self.checkForNull(anItem["data4"]!)
  ...... // Total 20 Columns
  
  let obj = [ d1, d2, d3, d4,.............,d20 ]
  
  OtherColobjects.addObject(obj)
  }
  dispatch_semaphore_signal(semaphore)
  } catch {
  return
  }
  }
  task.resume()
  
  dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER)
  self.NumberOfRows = returnData[0].count
  self.DTableDataArray = returnData[1] as! NSMutableArray
  }
  </code></pre>