I have written a "refresh" method which should show new items in the table view but it doesn't seem to be reloading the cells properly.
func refresh(sender:AnyObject) {
page = 1
self.data_request()
}
func data_request(){
let user_id = Data[0].valueForKey("user_id") as? String!
let url:NSURL = NSURL(string: "http://..../perspective/\(user_id!)/page/"+"\(page)" )!
let session = NSURLSession.sharedSession()
self.page = self.page + 1
let request = NSMutableURLRequest(URL: url)
request.HTTPMethod = "GET"
request.cachePolicy = NSURLRequestCachePolicy.ReloadIgnoringCacheData
let task = session.dataTaskWithRequest(request) {
(let data, let response, let error) in
guard let _:NSData = data, let _:NSURLResponse = response where error == nil else {
print("error")
return
}
var json: AnyObject?
do {
json = try NSJSONSerialization.JSONObjectWithData(data!, options: [])
}
catch {
return
}
guard let data_array = json as? NSArray else {
return
}
for i in 0..<data_array.count
{
if let add = data_array[i] as? NSDictionary
{
self.obj.append(Obj(data:add))
}
}
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.tableView.reloadData()
})
}
task.resume()
}
It doesn't update the cells.
And it sticks like that, without loading the data