当操作正在运行时,我无法在JSON模型CREATED BY ACCELERATOR中输入数据。 你能告诉我我做错了吗?
{
[super viewDidLoad];
NSLog(@"you are in a tableViewController");
self.title = @"NavigationOrdini";
NSURLRequest *req = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.stampa6x3.com/json.php?azione=ordini"]];
AFJSONRequestOperation* operation;
operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:req
success:^(NSURLRequest *request, NSURLResponse *response, id JSON)
{
[[ordiniModel alloc] initWithDictionary:JSON];
}
failure:^(NSURLRequest *request, NSURLResponse *response, NSError
*error, id JSON) {
[self setTitle:@"Dictionary"];
NSLog(@"failed! %d",[error code]);
}];
[operation start];
ordiniModel*test;
NSLog(@"il valore è %@",test.ordini.description);
}
答案 0 :(得分:0)
AFJSONRequestOperation是异步的,这意味着代码会在应用程序的其余部分运行时继续执行。代码实际完成时运行完成块。
所以试试:
NSLog(@"you are in a tableViewController");
self.title = @"NavigationOrdini";
ordiniModel *test; // <-- create variable here
NSURLRequest *req = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.stampa6x3.com/json.php?azione=ordini"]];
AFJSONRequestOperation* operation;
operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:req
success:^(NSURLRequest *request, NSURLResponse *response, id JSON)
{
test = [[ordiniModel alloc] initWithDictionary:JSON]; // <-- Assign here
NSLog(@"il valore è %@",test.ordini.description);
}
failure:^(NSURLRequest *request, NSURLResponse *response, NSError
*error, id JSON) {
[self setTitle:@"Dictionary"];
NSLog(@"failed! %d",[error code]);
}];
[operation start];