Brakes the scroll when you first start the application. If you scroll the table, everything starts to work smoothly. Is it possible to warm up the cache before displaying?

filling the table:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let card = CardDeck.instance.deck[indexPath.row] let cellId = "CellId" let cell = tableView.dequeueReusableCellWithIdentifier(cellId, forIndexPath: indexPath) as? SpyfallTableViewCell cell!.cellLabel?.text = card.name cell!.cellView?.image = card.image cell!.cellViewFull?.image = card.image cell!.backgroundColor = card.backgroudColor print(card.name) return cell! } 
  • With ios9, this can not be done, if only you yourself pre-download the data. In ios10 there will be an additional set of functions, something like a prediction which cells will be needed in the program soon. - Max Mikheyenko

1 answer 1

Do not do this. AT

 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell 

Just give the cell . And fill data asynchronously in

 func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) 

Then the UITableView scrolling will not slow down, just the data will appear with some delay in case of something heavy (and if you just fill in the text, you will not notice)

  • It became better, but the problem still persists. If you load pictures from the Internet, then everything works well, but in my case, the pictures are already loaded into Assets and the brakes remain. Maybe I misunderstood - Mikhail Sh.
  • Implementation: func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) { let cell:SpyfallTableViewCell = cell as! SpyfallTableViewCell let card = CardDeck.instance.deck[indexPath.row] cell.cellLabel?.text = card.name cell.backgroundColor = card.backgroudColor let image: UIImage = card.image dispatch_async(dispatch_get_main_queue()) { cell.cellView?.image = image cell.cellViewFull?.image = image } } func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) { let cell:SpyfallTableViewCell = cell as! SpyfallTableViewCell let card = CardDeck.instance.deck[indexPath.row] cell.cellLabel?.text = card.name cell.backgroundColor = card.backgroudColor let image: UIImage = card.image dispatch_async(dispatch_get_main_queue()) { cell.cellView?.image = image cell.cellViewFull?.image = image } } - Mikhail Sh.
  • @MikhailSh. Assign the text to dispatch_async(dispatch_get_main_queue()) . Wrap it all in dispatch_async(dispatch_get_global_queue... for the simplest case. And now let image: UIImage = card.image better not to store the pictures in the array, store the names of the pictures. And then let image = UIImage(named: card.imageName) and cell - VAndrJ am
  • Did as you say. On the emulator, micro friezes are almost non-independent, but on the device crashes. As I understand, this problem arises when reading pictures from the device, because when downloading from the Internet, the pictures just appear late. - Mikhail Sh.