Guest User

Untitled

a guest
Apr 26th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. class GZFeedTableViewController: UIViewController {
  2. lazy var postsRef = Database.database().reference().child("posts") // this is a path to the posts array in my Firebase database
  3. var posts = [GZPost]() // holds all the posts once they are downloaded
  4. var loadingPostCount = 0 // equal to the number of posts already downloaded, plus the number currently downloading.
  5. var idOfFinalPostInNextQuery: String? // used so that when we query database, we know where to go from
  6. let noOfPostsToLoad = 5 // the number of posts loaded in each query
  7. @IBOutlet weak var tableView: UITableView! // my tableview from the storyboard
  8. override func viewDidLoad() {
  9. super.viewDidLoad()
  10. self.tableViewSetup() // set up the tableview - see below
  11. self.loadSomeMorePosts(self.noOfPostsToLoad) // this method does the querying and loading of posts
  12. }
  13. private func tableViewSetup() {
  14. self.tableView.register(UINib.init(nibName: "GZFeedTableViewCell", bundle: nil), forCellReuseIdentifier: "GZFeedTableViewCell")
  15. let refreshControl = UIRefreshControl() // allows you to pull down on the UITableView to reload.
  16. let title = NSLocalizedString("Pull to refresh", comment: "Pull to refresh")
  17. refreshControl.attributedTitle = NSAttributedString(string: title)
  18. refreshControl.addTarget(self, action: #selector(refreshOptions(sender:)), for: .valueChanged)
  19. tableView.refreshControl = refreshControl
  20. }
  21. @objc private func refreshOptions(sender: UIRefreshControl) {
  22. self.reloadFeed()
  23. sender.endRefreshing()
  24. }
Add Comment
Please, Sign In to add comment