У меня есть UITableViewController
(вместо PFQueryTableViewController
), чтобы отобразить результаты моего запроса, и у меня есть массив хранения текстов. Поскольку запрос будет извлекать огромное количество данных, я хотел бы, чтобы мой tableView
загружал больше результатов, как только пользователь прокрутит страницу вниз. Есть много решений, но они либо в JSON, либо в ObjectiveC, и они кажутся мне очень расплывчатыми, поскольку я всего лишь новичок.Как загрузить больше ячеек в UITableView SWIFT
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. Не строите колесо самостоятельно, если не нужно. –