提问人: 提问时间:11/6/2018 最后编辑:Ani Papyan 更新时间:11/7/2018 访问量:46
如何使属性在方法中可用(非 Null)?
How can I make a property to be available (non-Null) inside a method?
问:
我定义了这个属性
@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]);
}
}];
}
这是 getParticipants数组:
-(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]);
}
}];
}
我的问题:
出于某种原因,我不知道,在我创建的 中保存一个 null 值,而在方法内的 和 事件中,保存正确的值。ObjectID
getArrayParticipants
PFQuery
viewDidLoad
我的猜测:
我认为它与同步/异步线程有关,正如之前所指出的那样
答: 暂无答案
评论
getParticipantsArray
getParticipantsArray
self.objectID