swift - 使用 swift 从表和解析数据源中删除数据

标签 swift uitableview parse-platform delete-row

您好,我一直在尝试创建一个连接到 do list 的解析。令我困扰的部分是当我想从表中删除一个元素并且我希望在数据库中删除相同的对象时。问题是我可以删除模拟器中的任何对象,但它会从数据库中删除下一个对象,而不是触发的对象。

override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
        if (editingStyle == UITableViewCellEditingStyle.Delete){

            LM.myList.removeAtIndex(indexPath.row)
            let myQuery = PFQuery(className: "list")
            myQuery.findObjectsInBackgroundWithBlock({ (Objects , error ) -> Void in
                if (error != nil){
                    print("Error was Found")
                }else if let Object = Objects {
                    for MyObject in Object {
                        if (MyObject["title"] as! String == LM.myList[indexPath.row].title  && MyObject["desc"] as! String  == LM.myList[indexPath.row].Description)

                        {
                         //print(LM.myList[indexPath.row ].Description)
                        //print(LM.myList[indexPath.row ].title)
                       //print(MyObject["title"] as! String)
                      //print(MyObject["desc"] as! String)
                       MyObject.deleteInBackground()
                       MyObject.saveInBackground()

                        }
                    }
                }
            }

            )

            tableView.deleteRowsAtIndexPaths( [indexPath] , withRowAnimation: UITableViewRowAnimation.Automatic)
        }
    }

提前致谢:)

最佳答案

LM.myList.removeAtIndex(indexPath.row)

此行将从本地数据源中删除目标对象,因此当您稍后查询它以比较名称时,您会发现错误的对象。

您不需要进行查询和迭代。您应该从本地数据源获取该对象,删除它(从服务器中删除它),然后从本地数据源和表中删除它。

关于swift - 使用 swift 从表和解析数据源中删除数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35394967/

相关文章:

ios - iphone 5 和 6 的导航栏图像

swift - 我如何使用 CALayer 创建一个圆圈?

swift - 下铸 Nib uitableviewcell

ios - 如何从 UiTableViewController 访问自定义 UITableViewCell 上的属性?

iOS Webview 应用程序,如何在 Webview 中打开 JSON 解析推送通知?

ios - admob 广告被关闭后执行 segue

ios - 从 UITableView 中删除值会导致崩溃

ios - 当子类化 UITableView 时如何自定义单元格准备

objective-c - 如何使用parse.com和Facebook 3.0 SDK获取共享对话框

java - 来自 parse.com 的空值查询