Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extension FeedViewController: UITableViewDelegate{
- func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
- let lastElement = venueData.count
- if indexPath.row == lastElement {
- // handle your logic here to get more items, add it to dataSource and reload tableview
- print(venueData.count)
- print("last")
- if(firstLoad){
- firstLoad = false
- return
- }
- let appendAmount = 10
- currentOffset = currentOffset+appendAmount
- let res = venueDataRequest(query:"Any",offset:10,amount:appendAmount)
- venueData.append(contentsOf: res )
- self.feedTableView.beginUpdates()
- self.feedTableView.insertRows(at: [IndexPath(row: venueData.count-appendAmount, section: 0)], with: .automatic)
- self.feedTableView.endUpdates()
- }
- }
- }
- import UIKit
- class FeedViewController: UIViewController {
- @IBOutlet weak var feedTableView: UITableView!
- let popularPlaces = getPopularPlaces()
- var firstLoad = true
- var currentOffset = 0
- var venueData = venueDataRequest(query:"Any",offset:0,amount:10)
- // var venueData: [FeedVenueData] = []
- override func viewDidLoad() {
- super.viewDidLoad()
- feedTableView.dataSource = self
- feedTableView.delegate = self
- // Do any additional setup after loading the view, typically from a nib.
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
- }
- extension FeedViewController: UITableViewDelegate{
- func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
- let lastElement = venueData.count
- if indexPath.row == lastElement {
- // handle your logic here to get more items, add it to dataSource and reload tableview
- print(venueData.count)
- print("last")
- if(firstLoad){
- firstLoad = false
- return
- }
- let appendAmount = 10
- currentOffset = currentOffset+appendAmount
- let res = venueDataRequest(query:"Any",offset:10,amount:appendAmount)
- venueData.append(contentsOf: res )
- self.feedTableView.beginUpdates()
- self.feedTableView.insertRows(at: [IndexPath(row: venueData.count-appendAmount, section: 0)], with: .automatic)
- self.feedTableView.endUpdates()
- }
- }
- }
- extension FeedViewController: UITableViewDataSource{
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return 1+venueData.count
- }
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- if(indexPath.row == 0){
- let cell = tableView.dequeueReusableCell(withIdentifier: "FeedPopularPlaceCollectionViewTableViewCell", for: indexPath) as! FeedPopularPlaceCollectionViewTableViewCell
- cell.setup()
- return cell
- }else{
- let cell = tableView.dequeueReusableCell(withIdentifier: "FeedVenueTableViewCell", for: indexPath) as! FeedVenueTableViewCell
- let pos = indexPath.row - 1
- cell.venueName.text = venueData[pos].name
- cell.venueImage.image = venueData[pos].image
- print(indexPath.row)
- return cell
- }
- }
- }
Add Comment
Please, Sign In to add comment