我试图重用一种方法从互联网上的JSON文件刷新表格视图。当我试图多次调用相同的方法时,我收到了这个错误:
EXEC_BAD_INSTRUCTION(代码= EXC_i386_INVOP,子代码= 0x0)
有人可以告诉我该怎么做吗?
谢谢你。
func topRefresh(sender:AnyObject){
self.notificationsDisplayed.removeAll()
var list=Array<Notification>()
//request json
let url = NSURL(string: jsonLink)!
let session = NSURLSession.sharedSession()
let request = NSMutableURLRequest(URL: url)
request.HTTPMethod="POST"
request.cachePolicy = NSURLRequestCachePolicy.ReloadIgnoringCacheData
let paramString="username=Axel&password=test"
request.HTTPBody = paramString.dataUsingEncoding(NSUTF8StringEncoding)
let task = session.dataTaskWithRequest(request) {
(data, response, error) -> Void in
let httpResponse = response as! NSHTTPURLResponse
if (httpResponse.statusCode == 200) {
do{
let jsonDict = try NSJSONSerialization.JSONObjectWithData(data!,options: .AllowFragments)
list=self.parseJson(jsonDict)
}catch {
print("Error with Json: \(error)")
}
}else{
print("HTTP Error")
}
//compare new data with past data
while(list.count>0){
let tmp=list.last
for notification in self.notifications {
if(tmp!.id==notification.severity){
list.removeLast()
}else{
self.notifications.insert(tmp!, atIndex: 0)
list.removeLast()
}
}
}
self.notificationsDisplayed=self.notifications
self.applyFilter()
self.refreshControl?.endRefreshing()
print("Finished")
}
task.resume()
}