Guest User

Untitled

a guest
May 21st, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.48 KB | None | 0 0
  1. extension FeedViewController: UITableViewDelegate{
  2. func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
  3. let lastElement = venueData.count
  4. if indexPath.row == lastElement {
  5. // handle your logic here to get more items, add it to dataSource and reload tableview
  6. print(venueData.count)
  7. print("last")
  8. if(firstLoad){
  9. firstLoad = false
  10. return
  11. }
  12. let appendAmount = 10
  13. currentOffset = currentOffset+appendAmount
  14.  
  15. let res = venueDataRequest(query:"Any",offset:10,amount:appendAmount)
  16. venueData.append(contentsOf: res )
  17.  
  18.  
  19. self.feedTableView.beginUpdates()
  20. self.feedTableView.insertRows(at: [IndexPath(row: venueData.count-appendAmount, section: 0)], with: .automatic)
  21. self.feedTableView.endUpdates()
  22.  
  23.  
  24. }
  25. }
  26. }
  27.  
  28. import UIKit
  29.  
  30. class FeedViewController: UIViewController {
  31.  
  32. @IBOutlet weak var feedTableView: UITableView!
  33.  
  34.  
  35. let popularPlaces = getPopularPlaces()
  36. var firstLoad = true
  37. var currentOffset = 0
  38. var venueData = venueDataRequest(query:"Any",offset:0,amount:10)
  39. // var venueData: [FeedVenueData] = []
  40.  
  41.  
  42. override func viewDidLoad() {
  43. super.viewDidLoad()
  44. feedTableView.dataSource = self
  45. feedTableView.delegate = self
  46. // Do any additional setup after loading the view, typically from a nib.
  47. }
  48.  
  49. override func didReceiveMemoryWarning() {
  50. super.didReceiveMemoryWarning()
  51. // Dispose of any resources that can be recreated.
  52. }
  53.  
  54. }
  55.  
  56. extension FeedViewController: UITableViewDelegate{
  57. func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
  58. let lastElement = venueData.count
  59. if indexPath.row == lastElement {
  60. // handle your logic here to get more items, add it to dataSource and reload tableview
  61. print(venueData.count)
  62. print("last")
  63. if(firstLoad){
  64. firstLoad = false
  65. return
  66. }
  67. let appendAmount = 10
  68. currentOffset = currentOffset+appendAmount
  69.  
  70. let res = venueDataRequest(query:"Any",offset:10,amount:appendAmount)
  71. venueData.append(contentsOf: res )
  72.  
  73.  
  74. self.feedTableView.beginUpdates()
  75. self.feedTableView.insertRows(at: [IndexPath(row: venueData.count-appendAmount, section: 0)], with: .automatic)
  76. self.feedTableView.endUpdates()
  77.  
  78.  
  79. }
  80. }
  81. }
  82.  
  83. extension FeedViewController: UITableViewDataSource{
  84. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  85. return 1+venueData.count
  86. }
  87.  
  88. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  89. if(indexPath.row == 0){
  90. let cell = tableView.dequeueReusableCell(withIdentifier: "FeedPopularPlaceCollectionViewTableViewCell", for: indexPath) as! FeedPopularPlaceCollectionViewTableViewCell
  91. cell.setup()
  92. return cell
  93. }else{
  94. let cell = tableView.dequeueReusableCell(withIdentifier: "FeedVenueTableViewCell", for: indexPath) as! FeedVenueTableViewCell
  95.  
  96. let pos = indexPath.row - 1
  97. cell.venueName.text = venueData[pos].name
  98. cell.venueImage.image = venueData[pos].image
  99.  
  100. print(indexPath.row)
  101. return cell
  102. }
  103. }
  104.  
  105. }
Add Comment
Please, Sign In to add comment