iphone - 在1个查询调用中更新多行。 Parse.com

标签 iphone ios parse-platform

我必须更新parse.com上一个表中的多个记录。它与将消息状态从未读更改为在多个记录中读取有关。
这是更新单个记录的示例。

PFQuery *query = [PFQuery queryWithClassName:@"GameScore"];

// Retrieve the object by id
[query getObjectInBackgroundWithId:@"xWMyZ4YEGZ" block:^(PFObject *gameScore, NSError *error) {

// Now let's update it with some new data. In this case, only cheatMode and score
// will get sent to the cloud. playerName hasn't changed.
[gameScore setObject:[NSNumber numberWithBool:YES] forKey:@"cheatMode"];
[gameScore setObject:[NSNumber numberWithInt:1338] forKey:@"score"];
[gameScore saveInBackground];

}];

如何更新多个记录?

为了更清楚,我必须执行类似以下的查询:
更新tableName SET messageStatus ='read'其中userId ='someId'

有什么帮助吗?

最佳答案

首先,您应该查询以下对象:

NSArray *arrayOfMessageIDs = @[@"2314312", @"312432423"]; // An array of your desired messages' ID
PFQuery *query = [PFQuery queryWithClassName:@"Message"];
        [query whereKey:@"messageID" containedIn:arrayOfMessageIDs];

然后,您遍历它们并更新它们的状态。
之后,保存所有阵列。
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error){
            if (error) {
                NSLog(@"%@", error);
                return;
            }
            for (PFObject *message in objects) {
                // Update your message
            }
            int success = [PFObject saveAll:objects];
            NSLog(@"Status %@", success? @"updated successfully": @"update failed");
}];

关于iphone - 在1个查询调用中更新多行。 Parse.com,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18459243/

相关文章:

ios - UIProgressView 作为健康栏并在按下按钮时更新。 swift

iphone - 直接从主 ViewController 加载另一个 UIView

node.js - 如何使用 Parse Server 登录/注册用户?

iphone - 解析.com : PFQueryTableViewController with PFUser

iphone - UIWebView 和取消点击手势

ios - iOS 上的 Android toast 消息

iphone - iOS - 后台本地通知

iOS 或 macOS 项目 : duplicate interface definition for ViewController

swift - 为什么 PFObject 不保存在后台?

iphone - 数组可以是顶级 JSON 对象吗? (在 Objective C,Stig Brautaset 的库中)