Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ViewController: UITableViewController {
- var items = [Int]()
- override func viewDidLoad() {
- super.viewDidLoad()
- tableView.backgroundColor = .white
- tableView.tableFooterView = UIView()
- tableView.register(UITableViewCell.self, forCellReuseIdentifier: "CELL_ID")
- DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
- self.addMoreRows([1,2,3,4,5])
- }
- DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
- self.addMoreRows([6,7,8,9,10])
- }
- }
- private func addMoreRows(_ data: [Int]) {
- self.items.append(contentsOf: data)
- var indexPaths = [IndexPath]()
- for i in 0...items.count - 1 {
- indexPaths.append(IndexPath(row: i, section: 0))
- }
- tableView.insertRows(at: indexPaths, with: .left)
- }
- override func numberOfSections(in tableView: UITableView) -> Int {
- return 1
- }
- override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return items.count
- }
- override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell = tableView.dequeueReusableCell(withIdentifier: "CELL_ID", for: indexPath)
- cell.textLabel?.text = "Cell #(indexPath.row)"
- return cell
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement