xcode - 更新 Parse 类中列中的值

标签 xcode swift parse-platform

我正在尝试更新 Parse 中“currentUploads”类中的列: Image here

这就是我正在尝试的

@IBAction func reportButtonAction(sender: AnyObject) {
    println("Report Button Pressed")
    let buttonPosition = sender.convertPoint(CGPointZero, toView: self.collectionView)
    let indexPath = self.collectionView.indexPathForItemAtPoint(buttonPosition)

    var alertMessage = NSString(format: "*User: %@\r *Text: %@\r *Created at %@", imageUploader[indexPath!.row], imageText[indexPath!.row]/*, imageCreated[indexPath!.row]*/)

    var reportAlert = UIAlertController(title: "Report Content", message:alertMessage as String, preferredStyle: UIAlertControllerStyle.Alert)

    reportAlert.addAction(UIAlertAction(title: "Yes", style: .Default, handler: { (action: UIAlertAction!) in
        println("Handle Report Logic here")
        self.reportContent()
    }))

    reportAlert.addAction(UIAlertAction(title: "Cancel", style: .Default, handler: { (action: UIAlertAction!) in
        println("Handle Cancel Logic here")
    }))

    presentViewController(reportAlert, animated: true, completion: nil)
}

func reportContent(){
    let someQuery = PFQuery(className: "currentUploads")
    someQuery.getObjectInBackgroundWithId("imageFile") {
        (updatedObject: PFObject?, error: NSError?) -> Void in
        if error != nil {
            print(error)
        } else if let updatedObject = updatedObject {
            updatedObject["reportedCount"] = "1"
            updatedObject.saveInBackground()
        }
    }
}

因此,我想将 func reportContent 中所选图像的“reportedCount”更新/增加到 1,但出现此错误:

[Error]: No results matched the query. (Code: 101, Version: 1.8.0) Optional(Error Domain=Parse Code=101 "No results matched the query." UserInfo=0x7fae8a484aa0 {error=No results matched the query., NSLocalizedDescription=No results matched the query., code=101})

最佳答案

我相信这是因为您查询了其中包含“imageFile”的所有实例,而不是实际的行。你想使用类似

someQuery.whereKey(objectId, EqualTo: objectId)

并使用

someQuery.findObjectsInBackgroundWithBlock

其中objectId 是您要更改reportedCount 的对象的对象ID。

那么你可以这样做

object.setValue(object["reportedCount"] as! Int + 1, forKey: "reportedCount")

这都是伪代码,但这是我在用户添加新 friend 时增加 friend 数量的方法。

关于xcode - 更新 Parse 类中列中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33192914/

相关文章:

swift - 在 Activity View Controller 中共享屏幕截图 - Swift

c# - 在 Xamarin.iOS 中阅读 Parse.com 推送负载

javascript - 单击 "submit"按钮后,将数据发送到 Parse

ios - 解析数组图像保存和获取

ios - 使用 UIDocumentPickerViewController 时如何快速从 CSV 获取数据

iPhone 计算器键盘

ios - 如何使 UICollectionViewFlowLayout 留在 UICollectionView 中

iphone - PhoneGap + Landscape : SplashScreen Loads Properly, 然后在闪烁和消失之前短暂旋转

ios - 有没有办法在 SwiftUI 中的动画之后执行函数?

xcode - 无法在终端 macOS 10.15.7 上安装 cocoapods