我已将名为“fid”的NSString的值设置为responseObject(参见下文)。 responseObject在NSLog'd时返回我想要的数据,但由于某种原因,当我NSLog进一步向下时,它是空的。我错过了什么吗?见代码:
·H
@property (nonatomic, assign) NSString *fid;
的.m
[DIOSFile fileSave:file success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"File uploaded!");
[file setObject:[responseObject objectForKey:@"fid"] forKey:@"fid"];
[file removeObjectForKey:@"file"];
fid = [responseObject objectForKey:@"fid"];
NSLog(@"%@",responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Failed to upload file!");
}];
NSDictionary *bodyValues = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:_itemDescrip.text, nil] forKeys:[NSArray arrayWithObjects:@"value", nil]];
NSDictionary *languageDict = [NSDictionary dictionaryWithObject:[NSArray arrayWithObject:bodyValues] forKey:@"und"];
[nodeData setObject:languageDict forKey:@"body"];
[nodeData setObject:@"storage_item" forKey:@"type"];
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
[dict setObject: [NSString stringWithFormat:@"%@", fid] forKey:@"fid"];
NSLog(@"%@", fid);
NSDictionary *fidLangDict = [NSDictionary dictionaryWithObject:[NSArray arrayWithObject:dict] forKey:@"und"];
[nodeData setObject:fidLangDict forKey:@"field_photo"];
[DIOSNode nodeSave:nodeData success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Node saved!");
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Node did not save!");
}];
答案 0 :(得分:3)
您正在调用异步方法。
日志语句“进一步向下”在fileSave方法完成之前很久就被执行了。 fileSave的两个回调将在遥远的未来某个时间被调用(可能是从现在开始的几秒钟)。
无论你想做什么,fid都必须在fileSave的完成块中完成。