如何在方法中使属性可用(非null)?

时间:2018-11-05 22:57:03

标签: ios objective-c methods parse-platform properties

我已定义此属性

@property (nonatomic, strong) NSString *ObjectID;

这是我的ViewDidLoad:

- (void)viewDidLoad {
    [super viewDidLoad];

    PFQuery *getObjectIDforRow = [PFQuery queryWithClassName:@"Event"];
    [getObjectIDforRow selectKeys:@[@"objectId"]]; // We decide which fields to get
    [getObjectIDforRow whereKey:@"Organizator" notEqualTo:PFUser.currentUser.username];
    [getObjectIDforRow whereKey:@"EventLocation" equalTo:Pointfrommap];

    // This method is to get the ObjectID for the selected row
    [getObjectIDforRow findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (!error) {
            // We save the Object ID found in a NSString
            self.ObjectID = [NSString stringWithFormat:@"%@", [objects valueForKey:@"objectId"]];

            NSLog(@"Object ID %@", self.ObjectID);

            [self getParticipantsarray]; // Here the exception won't come, but self.ObjectID is still null


        } else {
            // Log details of the failure
            NSLog(@"Error: %@ %@", error, [error userInfo]);
        }
    }];


}

这是getParticipantsarray:

-(void)getParticipantsarray{

    NSLog(@"Object ID is %@", self.ObjectID); // ID = Gj95aETEWq

     PFQuery *getArrayParticipants = [PFQuery queryWithClassName:@"Event"];
    [getArrayParticipants selectKeys:@[@"Participants"]]; // We decide which fields to get

    [getArrayParticipants whereKey:@"ObjectId" equalTo:self.ObjectID]; // Here ObjectID is Null 
        } else {
            // Log details of the failure
            NSLog(@"Error: %@ %@", error, [error userInfo]);
        }
    }];
}

我的问题:

出于某种原因,我不知道,ObjectID在我创建的getArrayParticipants PFQuery内保存一个空值,而在viewDidLoad中,则在方法内保存一个事件,保持正确的值。

我的猜测:

如前所述,我认为它与同步/异步线程有关

0 个答案:

没有答案