0
Hello, I have a tableview that will receive data on demand. however when I call scrollViewDidEndDragging function it has a call to tableview.reloadData() it replaces the previously loaded data.
Load Data
func carregaDados(pagina : Int)
{
let pg : String = String(pagina)
liberaLoad = false
var url : String = "minha url json rest"
var request : NSMutableURLRequest = NSMutableURLRequest()
request.URL = NSURL(string: url)
request.HTTPMethod = "GET"
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue(), completionHandler: { (response:NSURLResponse!, data: NSData!, error: NSError!) -> Void in
var error: AutoreleasingUnsafeMutablePointer<NSError?> = nil
let jsonResult : NSDictionary! = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: error) as? NSDictionary
if(jsonResult != nil){
//process json
let jsonUnico: NSMutableArray! = jsonResult["lista"] as? NSMutableArray
self.tableList = jsonUnico
self.tableView.reloadData()
self.liberaLoad = true
}else{
//nao foi possivel ler o json
}
})
}
Here I have the function that was to give an append in the dice
func scrollViewDidEndDragging(scrollView: UIScrollView, willDecelerate decelerate: Bool) {
let currentOffset : CGFloat = scrollView.contentOffset.y;
let maximumOffset : CGFloat = scrollView.contentSize.height - scrollView.frame.size.height;
if (maximumOffset - currentOffset <= -60.0 && liberaLoad) {
self.carregaDados(pagina:2)
}
}
Here my cellForRowAtIndexPath
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as CustonImageTableViewCell
let reeditList : NSMutableDictionary = self.tableList[indexPath.row] as NSMutableDictionary
let tipo = reeditList["tipo"] as? String
cell.lblTipo.text = tipo
return cell
}