Last active
February 28, 2020 19:43
-
-
Save yfujiki/45ce60ad14d8fdf054ca715fe5bb869e to your computer and use it in GitHub Desktop.
Cache Label
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private var labelCache = [IndexPath: UILabel]() | |
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
... | |
if labelCache[indexPath] == nil { | |
let label = UILabel() | |
label.text = ... | |
labelCache[indexPath] = label | |
} | |
let label = labelCache[indexPath]! | |
cell.contentView.addSubview(label) | |
... | |
return cell | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment