如何从服务器的NSMutableArray中删除JSON数据。
var jsondata : NSMutableArray!
func retrieve(){
let requrl: NSURL = NSURL(string: "http://localhost/tara/forvbc.php")!
let dataurl = NSData(contentsOfURL: requrl)
jsondata = try! NSJSONSerialization.JSONObjectWithData(dataurl!, options: .MutableContainers) as! NSMutableArray
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = thview.dequeueReusableCellWithIdentifier("thecell", forIndexPath: indexPath) as UITableViewCell
let asdasd = jsondata[indexPath.row]\
cell.textLabel?.text = jsondata["name"] as? String
return cell
}
我想使用commitEditingStyle
删除它override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == .Delete{
}
}
谢谢你的合作。
答案 0 :(得分:0)
按以下方式调整commitEditingStyle
代码:
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == .Delete {
jsondata.removeAtIndex(indexPath.row)
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic)
}
}