我想在用户滚动到表格底部时加载更多数据并创建其他单元格。我正在使用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
}
}