我正在尝试使用REST API从解析中删除图像。要删除它,我使用tableview和commitEditingStyle
来设置幻灯片和删除功能。但问题是它不会滑动。我已经阅读了文档,看了很多教程,我不知道为什么我的工作不起作用。下面是tableview的代码。谢谢!
func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return true
}
func tableView(tableView: UITableView!, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath!) {
println("Commit Editing Style \(editingStyle)")
}
func tableView(tableView: UITableView!, editActionsForRowAtIndexPath indexPath: NSIndexPath!) -> [AnyObject]! {
var deleteAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Delete", handler: {
(action: UITableViewRowAction!, indexPath: NSIndexPath!) in
println("Triggered delete action \(action) atIndexPath: \(indexPath)")
return
})
return [deleteAction]
}
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == .Delete {
var fileName = "uploaded_image.png"
let applicationID = "appidwritten"
let masterKey = "masterkeywritten"
let request = NSMutableURLRequest(URL: NSURL(string: "https://api.parse.com/1/files/\(fileName)")!)
request.HTTPMethod = "DELETE"
request.setValue(applicationID, forHTTPHeaderField: "X-Parse-Application-Id")
request.setValue(masterKey, forHTTPHeaderField: "X-Parse-Master-Key")
NSURLSession.sharedSession().dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in
println(response)
}).resume()
}
}