SHARE
TWEET

Untitled

a guest Jun 19th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class ViewController: UITableViewController {
  2.  
  3.     var items = [Int]()
  4.  
  5.     override func viewDidLoad() {
  6.         super.viewDidLoad()
  7.  
  8.         tableView.backgroundColor = .white
  9.         tableView.tableFooterView = UIView()
  10.         tableView.register(UITableViewCell.self, forCellReuseIdentifier: "CELL_ID")
  11.  
  12.         DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
  13.             self.addMoreRows([1,2,3,4,5])
  14.         }
  15.  
  16.         DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
  17.             self.addMoreRows([6,7,8,9,10])
  18.         }
  19.  
  20.     }
  21.  
  22.     private func addMoreRows(_ data: [Int]) {
  23.  
  24.         self.items.append(contentsOf: data)
  25.  
  26.         var indexPaths = [IndexPath]()
  27.  
  28.         for i in 0...items.count - 1 {
  29.             indexPaths.append(IndexPath(row: i, section: 0))
  30.         }
  31.  
  32.         tableView.insertRows(at: indexPaths, with: .left)
  33.     }
  34.  
  35.     override func numberOfSections(in tableView: UITableView) -> Int {
  36.         return 1
  37.     }
  38.  
  39.     override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  40.         return items.count
  41.     }
  42.  
  43.     override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  44.         let cell = tableView.dequeueReusableCell(withIdentifier: "CELL_ID", for: indexPath)
  45.         cell.textLabel?.text = "Cell #(indexPath.row)"
  46.         return cell
  47.     }
  48. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top