NSString 的值 returns 为 null,但不确定为什么?
Value of NSString returns null, but unsure why?
我已将名为 "fid" 的 NSString 的值设置为 responseObject(见下文)。 responseObject returns NSLog 时我想要的数据,但由于某种原因,当我 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!");
}];
您正在调用一个异步方法。
日志语句"further down"在fileSave方法完成之前很久就被执行了。 fileSave 的两个回调将在遥远的未来某个时候被调用(可能是从现在开始的许多秒)。
无论你想做什么,都必须在 fileSave 的完成块中完成。
我已将名为 "fid" 的 NSString 的值设置为 responseObject(见下文)。 responseObject returns NSLog 时我想要的数据,但由于某种原因,当我 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!");
}];
您正在调用一个异步方法。
日志语句"further down"在fileSave方法完成之前很久就被执行了。 fileSave 的两个回调将在遥远的未来某个时候被调用(可能是从现在开始的许多秒)。
无论你想做什么,都必须在 fileSave 的完成块中完成。