Hi
I’m trying to implement BETableView for iOS with paging enabled. I got it to work but not sure if this is the best way to implement it. Is there another way to use find and nextPage asynchronously?
class RootViewController: UIViewController {
@IBOutlet weak var tableView: BETableView!
var rowCount = 0
override func viewDidLoad() {
let query = BackendlessDataQuery()
query.whereClause = "gender = 'F' AND published = true"
query.queryOptions.sortBy = ["name"]
tableView.find(Name.ofClass(), dataQuery: query,
response: { (collection:BackendlessCollection?) in
self.rowCount = collection!.data.count
},
error: {(fault:Fault?) in
print("Server reported an error: \(fault)")
}
)
}
}
extension RootViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return rowCount
}
@objc(tableView:willDisplayCell:forRowAtIndexPath:)
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if indexPath.row == rowCount - 10 {
self.tableView.nextPageAsync({ (collection:BackendlessCollection?) in
self.rowCount += collection!.data.count
},
error: { (fault:Fault?) in
print("Server reported an error: \(fault)")
}
)
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let name = self.tableView.getDataFor(indexPath) as! Name
let cell = tableView.dequeueReusableCell(withIdentifier: "Name", for: indexPath)
configure(cell: cell, entity: name)
return cell
}
func configure(cell:UITableViewCell, entity:Name) {
cell.textLabel?.text = entity.name
}
}
Thank you for any feedback