如何删除NSMutableArray的数据

时间:2016-07-04 21:59:58

标签: ios swift

如何从服务器的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{

    }
}

谢谢你的合作。

1 个答案:

答案 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)
    }
}