使用Swift和Parse从UITableViewCell中删除背景中的某些对象

时间:2015-09-03 01:56:12

标签: ios swift uitableview parse-platform

所以我有一个UITableViewCell,我想删除tableView中的图像。但我也想从Parse数据库中删除给定的对象。

我将图像对象保存在在线Parse框架和Local Datastore

for i in images{

  var imageNames = i.thumbnailImage
  var imageFile = PFFile(data: UIImagePNGRepresentation(imageNames))

  //Pin the objects here!!
  var imageObject = PFObject(className: "img")
  imageObject["theImg"] = imageFile
  //imageObject["user"] = PFUser.currentUser()?.username
  imageObject.pinInBackgroundWithName("imgs")

  var objID = imageObject.objectId
  imageObject.pinInBackgroundWithBlock({ (success, error) -> Void in
    if error == nil{

      println("Object Saved!!")
      imageObject.save()
      println(objID)
      self.imagesFromParse.append(imageNames!)

      self.tableView.reloadData()
    } else {
      println(error)
    }
})

然后我在这里调用了删除UITableViewCell函数 -

 override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {

    var cell:nudeCell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! nudeCell

    if editingStyle == UITableViewCellEditingStyle.Delete{

        if self.imagesFromParse.count >= 1{

            self.imagesFromParse.removeAtIndex(indexPath.row)

           //Here is where i want to delete the object from the localDatastore and the online framwork
        }
    }
}

问题是当我尝试在后台删除对象时。我不知道如何在给定的indexPath中获取要删除的特定对象ID。

0 个答案:

没有答案