I have a UITableViewController
(instead of a PFQueryTableViewController
) to display my query results and I have an array storing texts. Since the query would fetch huge amount of data, I would like my tableView
to load more results once the user scroll to the bottom. There are many solutions out there but they're either in JSON or ObjectiveC and they seem really vague to me, as I am just a beginner.
class queryResultsViewController: UITableViewController {
var texts = [String]()
override func viewDidLoad() {
super.viewDidLoad()
let query = PFQuery(className: "allPosts")
query.whereKey("userId", equalTo: (PFUser.currentUser()?.objectId)!)
query.orderByDescending("createdAt")
query.findObjectsInBackgroundWithBlock { (posts, error) -> Void in
if let posts = posts {
self.texts.removeAll(keepCapacity: true)
for post in posts {
self.captionOne.append(post["text"] as! String)
self.tableView.reloadData()
}
}
}
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return texts.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! theCell
cell.TextView.text = texts[indexPath.row]
return cell
}