如何从Parse列中存储的数组中删除对象

时间:2015-08-12 13:46:55

标签: ios swift uitableview parse-platform uibutton

所以,我在Parse.com上创建了一个名为Posts的课程。这是课程Posts enter image description here

的图像

在这里,您可以在objectId列中看到所有Postslikes列中的objectIds我正在保存喜欢帖子的用户的ObjectIds ..所以基本上,如果用户点击不像按钮,则应删除当前用户的ID。这是我目前的代码:

 var query:PFQuery = PFQuery(className: "Posts")
 query.whereKey("objectId", equalTo: postData.objectId!)
 query.whereKey("likes", equalTo: PFUser.currentUser()!.objectId!)
 query.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in

  if let objects = objects {

   for object in objects {

    object.deleteInBackground()

    }

    }
 })

但它会删除整行而不是当前用户的用户ID ..

3 个答案:

答案 0 :(得分:2)

您可以使用Image img = Image.FromFile(fname) Clipboard.SetImage(img); RichTextBox1.Paste(); 仅从阵列中删除此单个对象。执行此操作后,请调用$('input').change(function(){ if($('#count').val() > $('#select option:last-child()').data("number")) { $('#select option[data-number="6"]').attr('disabled', 'disabled'); } else { $('#select option[data-number="6"]').removeAttr('disabled'); $('#select option[data-number="'+$('#count').val()+'"]').attr('selected', 'selected'); } }); 将更改保存回服务器。

另请参阅:https://www.parse.com/docs/ios/guide#objects-arrays

答案 1 :(得分:0)

我相信你将userID作为字符串而不是指针存储在你喜欢的数组中。

在你的代码中,关键字“喜欢”是一个数组类型,但你想查询一个字符串类型的objectId,显然parse不会找到任何匹配此查询的列。

所以在你的情况下,你想删除你喜欢的数组中的一个字符串(目标c代码)

PFQuery *query = [PFQuery queryWithClassName@"Posts"];
[query whereKey:@"objectId" equalTo:postData.objectId];
[query findObjectsInBackgroundWithBlock:^(NSArray *object, NSError *error)
     {
         if (! error)
         {
             //get the post object, index 0 because each post has 1 unique ID
             PFObject *thisObject = [object objectAtIndex:0];
             //get the likes array
             NSMutableArray *array = [[NSMutableArray alloc]initWithArray:thisObject[@"likes"]];
             [array removeObject:/* your user id*/];
             //save the new array
             [thisObject setObject:array forKey:@"likes"];
             [thisObject saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error){
                 if (succeeded)
                 {
                     //success
                 }
             }];
         }
     }];

答案 2 :(得分:0)

我已经使用您的方法从其他用户朋友列表中删除用户objectID,而是将其添加到用户被阻止的朋友列表中,两者都在解析时的数组中。谢谢

.data
INPUT_STRING:   .string "Give me a string: "
SCANF_STRING:   .string "%11s"      ##### Accept only 11 characters (-1 because terminating null)
PRINTF_STRING:  .string "String: %s\n"

.text
    .globl main
    .type main, @function
main:
    pushl %ebp
    movl %esp, %ebp
    subl $32, %esp

    mov $32, %ecx
    mov %esp, %edi
    mov $88, %al
    rep stosb

    pushl $INPUT_STRING
    call printf                         # printf("Give me a string: ")
    addl $4, %esp

    leal -12(%ebp), %eax
    pushl %eax                          # char*
    pushl $SCANF_STRING                 # "%s"
    call scanf                          # scanf("%s", char*)
    addl $8, %esp

    leal -12(%ebp), %eax
    pushl %eax                          # char*
    pushl $PRINTF_STRING            ##### '$' was missing
    call printf                         # printf("String: %s\n")
    addl $8, %esp                   ##### 16 was wrong. Only 2 DWORD à 4 bytes were pushed

    leave
    ret