0

操作実行中、CREATEDBYACCELERATORのJSONモデルにデータを入力できません。私が間違っていることを教えてもらえますか?

{
    [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);

}
4

1 に答える 1

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];
于 2013-03-26T20:34:55.693 に答える