2011-01-06 4 views
0

이 코드가 무슨 문제입니까? xml 데이터를 문자열로 변환하여 로그에 인쇄한다고 가정합니다. 그러나 아무 것도 인쇄하지 않습니다.objective-c xml을 string으로 변환하는 방법은 무엇입니까?

-(IBAction)request:(id)sender 
{ 
    NSURL *url = [NSURL URLWithString:@"http://api.twitter.com/1/statuses/public_timeline.xml"]; 
    theRequest = [[NSMutableURLRequest alloc] initWithURL:url]; 
    theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; 
    receivedData=[[NSMutableData data] retain]; 

    NSString *s = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding]; 
    NSLog(@"%@", s); 
    [s release]; 

//parser = [[NSXMLParser alloc] initWithData:receivedData]; 
//[parser setDelegate:self]; 
//[parser parse]; 
    } 

및 아이디어? 사전

답변

2
receivedData=[[NSMutableData data] retain]; 

에서

덕분에 당신은 빈 데이터를 초기화하고, 그 후, URL에 연결 및 URL 요청이 사용되지 않습니다. 초기화 된 데이터는 비어 있습니다.

+0

감사합니다. 나는 왜이 명백한 실수에주의를 기울이지 않았는지 알지 못합니다. 데이터를 받기 위해 대리인 메서드를 사용해야합니다. 덕분에 지금 작동 중입니다. :) – ahmed

관련 문제