【发布时间】:2016-02-23 13:15:07
【问题描述】:
我有一个UITableViewController(而不是PFQueryTableViewController)来显示我的查询结果,并且我有一个存储文本的数组。由于查询会获取大量数据,我希望我的tableView 在用户滚动到底部后加载更多结果。那里有很多解决方案,但它们要么是 JSON 要么是 ObjectiveC,它们对我来说似乎真的很模糊,因为我只是一个初学者。
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
}
【问题讨论】:
-
那个叫无限滚动,去github试试。如果没有必要,不要自己造轮子。
标签: swift uitableview pfquery