Last active
December 11, 2018 09:39
-
-
Save Lomiren/7fe762e838a5a14649a9b7d95c7daae8 to your computer and use it in GitHub Desktop.
This file contains 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
import UIKit | |
struct tvcmodel:Codable { | |
let smileSad = "🥺" | |
let smileHappy = "😀" | |
let num: Int | |
} | |
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { | |
@IBOutlet var tableView: UITableView? | |
open var cahcedCells: [UITableViewCell] = [] | |
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
return 1000 | |
} | |
func cells_setup() { | |
for i in 0...1000 { | |
var cell = UITableViewCell() | |
var cell_Model = tvcmodel(num: i) | |
var cellSmileText = i % 2 == 0 ? cell_Model.smileHappy : cell_Model.smileSad | |
cell.textLabel?.text = cellSmileText + " \(cell_Model.num)" | |
cahcedCells.append(cell) | |
} | |
} | |
override func viewDidLoad() { | |
self.tableView?.delegate = self | |
self.tableView?.dataSource = self | |
self.tableView?.rowHeight = UITableView.automaticDimension | |
self.tableView?.estimatedRowHeight = 50 | |
self.cells_setup() | |
self.tableView?.reloadData() | |
super.viewDidLoad() | |
} | |
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
let cell:UITableViewCell = UITableViewCell() | |
return cahcedCells[indexPath.row] | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment