Io 正在Parse.com中检索指针列

Io 正在Parse.com中检索指针列,io,parse-platform,Io,Parse Platform,我有两个班,一个班和一个班。在miaEvents上,我有一个名为“locationEvent”的列指针类型。我正在尝试从该列检索数据。我就是这样做的 __block NSString *myString; PFObject *obj = [self.event objectForKey:@"locationEvent"]; [obj fetchInBackgroundWithBlock:^(PFObject *object, NSError *error) {

我有两个班,一个班和一个班。在miaEvents上,我有一个名为“locationEvent”的列指针类型。我正在尝试从该列检索数据。我就是这样做的

__block NSString *myString;

    PFObject *obj = [self.event objectForKey:@"locationEvent"];
    [obj fetchInBackgroundWithBlock:^(PFObject *object, NSError *error) {
        if (!error) {
            myString = [object objectForKey:@"Name"];
        }
    }];



        NSLog(@"Name %@", myString);

我的输出返回“Name(null)”。不知道为什么会这样。请注意。

这是因为FetchInBackgroundithBlock异步执行请求

你得走了

NSLog(@"Name %@", myString);
如果要显示/使用提取的对象,请在FetchInBackgroundithBlock的回调块中:

__block NSString *myString;
PFObject *obj = [self.event objectForKey:@"locationEvent"];
[obj fetchInBackgroundWithBlock:^(PFObject *object, NSError *error) {
    if (!error) {
        myString = [object objectForKey:@"Name"];
        NSLog(@"Name %@", myString);
    }
}];

是的,但是我怎么能在块外使用这个变量呢?你不能。你必须在街区内利用它。基本上,在块外创建myString变量没有意义。不要忘记,在查询miaEvents时,可以指定要包含关系locationEvent的对象。这将节省您以后获取它的时间。您应该查看对象/关系数据,从“默认情况下,获取对象时,不会获取相关对象”开始。祝您好运!谢谢你,伙计,我从我的表中包含了关于PFQuery的查询,它工作得非常好。谢谢