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