无论多么简单,我仍然在努力用
更新PFObject数据-(IBAction)postMessageTapped:(id)sender{
[self hideTextField:_messageTextField];
NSMutableArray *myNewMessageArray=[[NSMutableArray alloc]init];
[myNewMessageArray insertObject:_messageTextField.text atIndex:0];
[myNewMessageArray insertObject:[PFUser currentUser] atIndex:1];
PFQuery *query = [PFQuery queryWithClassName:ClassName];
[query getObjectInBackgroundWithId:currentId block:^(PFObject *object, NSError *error) {
object[messagingArray] = myNewMessageArray;
[object saveInBackground];
}];
}
目的是从文本字段和当前用户名获取消息字符串,并将其放入一个数组中,然后更新解析数据库中存在的数组。但是,
Cannot do a comparison query for type: (null)
当用户点击发布消息的按钮时,出现。
有没有人有可能的解决方案?
编辑:
PFQuery *query = [PFQuery queryWithClassName:ClassName];
[query whereKey:@"location" nearGeoPoint:locationOfSelectedPin];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!objects) {
NSLog(@"The getFirstObject request failed.");
} else {
for(PFObject *objectTest in objects){
NSLog(@"Successfully retrieved the object.");
objectTest[@"messagingArray"]=myNewMessageArray;
[objectTest saveInBackground];
}
}
}];
我也尝试使用它来更新我的数据,并成功检索到对象'被打印3次,但之后会出现三行错误,找不到更新的对象'
答案 0 :(得分:1)
检查您在哪里设置objectId
- 此错误意味着它无法获取对象,因为您将nil值传递给数据库以进行查找。
这里有一些处理异常的代码:
if (!currentId) {
NSLog(@"Your currentId object is nil! Check your assignment.");
}
else {
PFQuery *query = [PFQuery queryWithClassName:ClassName];
[query getObjectInBackgroundWithId:currentId block:^(PFObject *object, NSError *error) {
object[messagingArray] = myNewMessageArray;
[object saveInBackground];
}];
}