我想在用户滚动到表格底部时加载更多数据并创建额外的单元格。我正在使用 JSON 数据和 MySql。
func dataJsonFromURL(url:String)->NSArray
{
if let data = NSData(contentsOfURL: NSURL(string: url)!) {
return ((try! NSJSONSerialization.JSONObjectWithData(data, options: [])) as! NSArray)
}
else{
return data
}
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCellWithIdentifier("NCell", forIndexPath: indexPath) as! TableViewCell22
cell.backgroundColor = UIColor .clearColor()
let mindata = (data[indexPath.row] as! NSDictionary)
}
最佳答案
你必须使用这个方法
override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
let lastElement = dataSource.count - 1
if indexPath.row == lastElement {
// handle your logic here to get more items, add it to dataSource and reload tableview
}
}
关于swift - UITableView 滚动到底部时加载更多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34588837/