我对Objective-C相当新,所以请原谅我可能很难看的代码,但是目前我有以下函数从parse中检索对象,然后我打算用它来填充Xcode中的列表视图。
- (void)retrieveEventsFromParse {
PFQuery *query = [PFQuery queryWithClassName:@"events"];
//retrieve all columns (will be fixed once a userId value is added)
[query whereKey:@"location" notEqualTo:@""];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
// The find succeeded.
NSLog(@"Successfully retrieved %lu locations.", (unsigned long)objects.count);
// Do something with the found objects
for (PFObject *object in objects) {
NSLog(@"%@", object.objectId);
}
} else {
// Log details of the failure
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];
}
但是我似乎只能检索objectId,而是想要检索一个名为'location'的值,该值存储为字符串。我该怎么做呢?
抱歉,我对此非常陌生,所以如果你能在具体的例子中具体说明,那么谢谢。答案 0 :(得分:0)
代码看起来还不错。要开始使用,请跳过whereKey
限定以确保您可以获得一些对象。使用objectForKey:
上的PFObject
方法访问列的值...
PFQuery *query = [PFQuery queryWithClassName:@"events"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
NSLog(@"Successfully retrieved %lu locations.", (unsigned long)objects.count);
// Do something with the found objects
for (PFObject *object in objects) {
// assuming location is a string, change the type if it isn't
NSString *location = [object objectForKey:@"location"];
NSLog(@"object with id has location %@ %@", object.objectId, location);
}
} else {
// Log details of the failure
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];