title: UITableView lag when scroll
body: <p>I use a tableView , manually cached cells , but when I scroll I get a little lag .
  This is my code : </p>
  
  <pre><code>    func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -&gt; CGFloat
  {
  
  
      var realRow = indexPath.row / 2
      if indexPath.row / 2 &gt; self.SUGGESTED_USERS_RATE &amp;&amp; suggestedUsers.count &gt; 0
      {
          --realRow
      }
      if indexPath.row / 2 &gt; self.SUGGESTED_RADIOS_RATE &amp;&amp; suggestedRadioStations.count &gt; 0
      {
          --realRow
      }
  
      if indexPath.row % 2 == 1
      {
          return self.CELL_MARGIN
      }
      else if indexPath.row / 2 == self.SUGGESTED_USERS_RATE &amp;&amp; suggestedUsers.count &gt; 0
      {
          return self.SUGGESTED_USERS_CELL_HEIGHT
      }
      else if indexPath.row / 2 == self.SUGGESTED_RADIOS_RATE &amp;&amp; suggestedRadioStations.count &gt; 0
      {
          return self.SUGGESTED_USERS_CELL_HEIGHT
      }
      else
      {
          return self.CELLS_HEIGHT[realRow]//[indexPath.row / 2 - indexPath.row / (self.SUGGESTED_USERS_RATE * 2 + 2)]
      }
  </code></pre>
  
  <p>//            let row = indexPath.row / 2</p>
  
  <pre><code>}
  
  func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell
  {
      var realRow = indexPath.row / 2
  
      if indexPath.row / 2 &gt; self.SUGGESTED_USERS_RATE &amp;&amp; suggestedUsers.count &gt; 0
      {
          --realRow
      }
      if indexPath.row / 2 &gt; self.SUGGESTED_RADIOS_RATE &amp;&amp; suggestedRadioStations.count &gt; 0
      {
          --realRow
      }
  
  
  
  
      if indexPath.row % 2 == 1
      {
          let cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "")
          cell.backgroundColor = UIColor.grayColor().colorWithAlphaComponent(0.3)
  
          cell.selectionStyle = .None
  
          addSeperatorsToView(cell.contentView, width: self.bounds.width,
              height: self.CELL_MARGIN, up: true, down: true, left: false, right: false)
  
          return cell
      }
      else if indexPath.row / 2 == self.SUGGESTED_RADIOS_RATE &amp;&amp; suggestedRadioStations.count &gt; 0
      {
          let cell = SuggestedUsersCell(width: self.bounds.width, height: self.SUGGESTED_USERS_CELL_HEIGHT, radios: suggestedRadioStations.prefix(5) + [])
          return cell
      }
      else if indexPath.row / 2 == self.SUGGESTED_USERS_RATE &amp;&amp; suggestedUsers.count &gt; 0
      {
          let cell = SuggestedUsersCell(width: self.bounds.width, height: self.SUGGESTED_USERS_CELL_HEIGHT, users: suggestedUsers.prefix(5)  + [])
          return cell
      }
      else
      {
          var cell : ActivityTableViewCell
  
          if let myCell = self.cells_cache[realRow]
          {
              cell = myCell
          }
          else
          {
              let activity = self.actevetiesArr[realRow]
  
              cell = ActivityTableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: self.CELL_ID,
                  height: self.CELLS_HEIGHT[realRow],
                  width: self.bounds.width, activity: activity ,
                  index : realRow  ,
                  delegate : self)
  
              self.cells_cache[realRow] = cell
  
          }
  
  
  
          cell.userInteractionEnabled = true
          cell.selectionStyle = .None
  
          return cell
      }
  }
  
  func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int
  {
      var count = self.actevetiesArr.count * 2
  
      if self.actevetiesArr.count &gt; self.SUGGESTED_USERS_RATE
      {
          count = count + 2
      }
      if self.actevetiesArr.count &gt; self.SUGGESTED_RADIOS_RATE
      {
          count = count + 2
      }
  
      if self.actevetiesArr.count &lt; max(self.SUGGESTED_USERS_RATE , self.SUGGESTED_RADIOS_RATE)
      {
          count += 2
          self.SUGGESTED_RADIOS_RATE = 1
          self.SUGGESTED_USERS_RATE = 0
      }
      else
      {
          self.SUGGESTED_USERS_RATE = SUGGESTED_USERS_INDEX
          self.SUGGESTED_RADIOS_RATE = SUGGESTED_RADIOS_INDEX
      }
  
      if suggestedRadioStations.count == 0
      {
          count -= 2
      }
  
      if suggestedUsers.count == 0
      {
          count -= 2
      }
  
      return count//(self.actevetiesArr.count + (self.actevetiesArr.count 
  }
  </code></pre>
  
  <p>what is the problem ??! , I don't do a huge amount of code in cellForRowAtIndexPath.
  Note : cell_cache is a dictionary ==> [Int:  ActivityTableViewCell</p>