Upgrade to Pro — share decks privately, control downloads, hide ads and more …

tableViewとcoolectionviewのパフォーマンスチューニング

kichikuchi
February 02, 2017

 tableViewとcoolectionviewのパフォーマンスチューニング

kichikuchi

February 02, 2017
Tweet

More Decks by kichikuchi

Other Decks in Technology

Transcript

  1. FOE3FGSFTIJOH CFGPSF apiClient.download { result in switch result { case

    .success: self.refreshControl.endRefreshing() self.tableView.reloadData() case .failure(_): break } } "1*Λୟ͍ͨޙৗʹFOE3FGSFTIJOH ͍ͯͨ͠
  2. FOE3FGSFTIJOH BGUFS apiClient.download { result in switch result { case

    .success: if refreshControl.isRefreshing { refreshControl.endRefreshing() } self.tableView.reloadData() case .failure(_): break } } JT3FGSFTIJOHΛར༻ͯ͠ ඞཁͳ͚࣌ͩFOE3FGSFTIJOH ͢Δ
  3. ߴ͞ܭࢉॲཧCFGPSF func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat

    { let cell = tableView.dequeueReusableCell(withIdentifier: "Cell")! return cell.frame.size.height } IFJHIU'PS3PX"UͰ DFMMΛΠϯελϯεԽ͍ͯͨ͠
  4. ߴ͞ܭࢉॲཧBGUFS lazy var cellHeight: CGFloat = { let cell =

    self.tableView.dequeueReusableCell(withIdentifier: "Cell")! return cell.frame.size.height }() func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { return cellHeight } MB[ZWBSͰDFMM)FJHIUΛఆٛ͠ DFMMͷΠϯελϯεԽΛҰ౓͚ͩʹͨ͠
  5. WJTJCMF$FMMTͰݟ͑ͯΔ෼͚ͩߋ৽ collectionView.visibleCells.forEach { cell in if let indexPath = collectionView.indexPath(for:

    cell) { cell.update(with: products[indexPath.row]) } } DFMMͷߋ৽͚ͩͰ͖ΔͷͰ SFMPBE%BUB ͱൺ΂Δͱѹ౗తʹܰྔʂʂ
  6. XJMM%JTQMBZDFMM func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath:

    IndexPath) { cell.update(with: products[indexPath.row]) } DFMM͕දࣔ͞ΕΔ௚લʹߋ৽͢Δ͜ͱͰ ߋ৽࿙ΕΛͳ͘͢ʂ
  7. ଞʹ΋৭ʑ͋Δ UBCMF7JFX tableView.reloadData() tableView.reloadRows(at: [IndexPath], with: UITableViewRowAnimation) tableView.reloadSections(sections: IndexSet, with:

    UITableViewRowAnimation) DPMMFDUJPO7JFX collectionView.reloadData() collectionView.reloadItems(at: [IndexPath]) collectionView.reloadSections(sections: IndexSet)
  8. ·ͱΊ w ೋͭͷ࣮ྫΛڍ͛ͯνϡʔχϯάํ๏Λ঺հͨ͠ w 6*ʹؔ͢Δॲཧ͸ඞཁͳ࣌ʹ͚ͩ͢Δ w FOE3FGSFTIJOH ͸JT3FGSFTIJOHͷ͚࣌ͩݺͿ w ߴ͞ܭࢉॲཧ

    IFJHIU'PS3PX"U TJ[F'PS*UFN"U ͸ܰྔ ʹ͢Δ w Ή΍ΈʹSFMPBE%BUB ͠ͳ͍ w WJTJCMF$FMMT SFMPBE3PXT SFMPBE4FDUJPOTͳͲͰࡁΉ ͳΒͦͪΒͰࡁ·͢