2011-07-18 12 views
1

Google place APIからiphoneアプリケーションを開発しています。そのためには、データを取得するためのJSON解析を行っています。私は1つのクラスを作ってきたし、その中で、私はJsonParse.mファイル次の方法でこれらのメソッド を足すよJSONの構文解析のためにiphoneでjsonの解析時にnsurldelegatesメソッドが呼び出されない理由

が書かれている:

- (void)initWithURLString:(NSString *)aURLString parameter:(UIViewController *)viewController 
{ 

    NSURL *url = [NSURL URLWithString:aURLString]; 
     NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; 
    connection=[[NSURLConnection alloc] initWithRequest:request delegate:viewController]; 

} 

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 
{ 
    [responseData setLength:0]; 
} 

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 
{ 
    [responseData appendData:data]; 
} 

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error 
{ 
    label.text=[NSString stringWithFormat:@"error in the connection %@",[error description]]; 
} 

-(void)connectionDidFinishLoading:(NSURLConnection *)connection 
{ 
    NSString *responsestring=[[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; 

    NSLog(@"response string is %@",responsestring); 

    NSError *error; 
    SBJSON *json=[[SBJSON new]autorelease]; 
    NSMutableDictionary *response=[NSMutableDictionary dictionary]; 
    response=[json objectWithString:responsestring error:&error]; 

    NSLog(@"values in the dictionary is %@",[response valueForKey:@"results"]);   
} 

そして、私は以下のようにviewcontrollerクラスからメソッドを呼び出しています:

JsonParse *obj=[[JsonParse alloc] init]; 
[obj initWithURLString:urlstr parameter:self]; 

しかし、私は唯一のinitwithurlメソッドが呼び出され、デバッグしていたときに、他の接続デリゲートメソッドが呼び出されていません。
以前は、すべてのメソッドが呼び出されたときに、同じクラスのメソッドをviewcontrollerクラスに作成しました。データを作成することができました。
同じviewcontrollerクラスで、データを複数回(異なるURLで1回以上)解析したいので、私は別のクラスにこのメソッドを記述しました。

誰も、これらのメソッドが呼び出されない理由、または同じクラスで何回も解析する方法を知っていますか?チュートリアルやそのサンプルコードは?

答えて

0

で:

// the delegate must be self 
connection=[[NSURLConnection alloc] initWithRequest:request 
              delegate:viewController]; 

デリゲートこれらのメソッドはJsonParseで実装されているので、と呼ばれる取得するためにこれらのメソッドのためにselfする必要があります。

関連する問題