2011-08-04 3 views
0

나는 LazyTableImages와 같이 비동기 적으로 Twitter JSON URL에 대한 이미지 파일을 다운로드하는 방법을 알아 내려고하고있다. 이 스크롤의 클라이언트 환경을 죽이지 않는되도록의 tableview를 스크롤하는 동안JSON 프로필 이미지 URL에 대한 트위터에 대한 피드

{ 
"completed_in": 0.132, 
"max_id": 99177223541628930, 
"max_id_str": "99177223541628928", 
"next_page": "?page=2&max_id=99177223541628928&q=mobile&rpp=1", 
"page": 1, 
"query": "mobile", 
"refresh_url": "?since_id=99177223541628928&q=mobile", 
"results": [ 
    { 
     "created_at": "Thu, 04 Aug 2011 17:57:47 +0000", 
     "from_user": "twhp_Bastary", 
     "from_user_id": 235609046, 
     "from_user_id_str": "235609046", 
     "geo": { 
      "coordinates": [ 
       -2.6766, 
       118.8793 
      ], 
      "type": "Point" 
     }, 
     "id": 99177223541628930, 
     "id_str": "99177223541628928", 
     "iso_language_code": "en", 
     "metadata": { 
      "result_type": "recent" 
     }, 
     "profile_image_url": "http://a1.twimg.com/profile_images/1431110298/315762105_normal.jpg", 
     "source": "<a href="http://ubersocial.com" rel="nofollow">ÜberSocial for BlackBerry</a>", 
     "text": "RT @DamnItsTrue: Good friends are priceless! #DamnItsTrue http://myloc.me/m9Kot", 
     "to_user_id": null, 
     "to_user_id_str": null 
    } 
], 
"results_per_page": 1, 
"since_id": 0, 
"since_id_str": "0" 

}

핵심 profile_image_URL 될 비동기 적으로 이미지를로드 할 필요가 : 같은 JSON 파일 보인다. JSON을로드하는 데 사용되는 코드는 각 태그를 키로 사용하여 NSDictionary를 사용합니다.

NSDictionary *tweets = [twitter objectAtIndex:[indexPath row]]; 

cell.textLabel.text = [tweets objectForKey:@"text"]; 
cell.textLabel.font = [UIFont systemFontOfSize:14]; 

NSString *URL = [tweets objectForKey:@"profile_image_url"]; 
NSURL *url = [NSURL URLWithString:[tweets objectForKey:@"profile_image_url"]]; 
NSData *Tweetdata = [NSData dataWithContentsOfURL:url]; 
cell.imageView.image = [UIImage imageWithData:Tweetdata]; 

답변

0

나는 스탠포드 CS193P 샘플 코드의 ImageLoadingOperation 클래스를 사용합니다.

Google은이를 사용하여 다양한 프로젝트를 찾습니다.

블록을 사용하여 최신 방법을 찾으면 결과를 게시하십시오.

최신 SDK로 가장 효율적인 방법을 알고있는 것이 좋습니다.

편집 -

http://www.stanford.edu/class/cs193p/cgi-bin/drupal/downloads-2010-winter 페이지

이 프로젝트는 플리커에서 사진의 다운로드 할 수있는 스레드 방식을 사용입니다 연결합니다. 이것이 내가 사용한 것입니다 : http://www.stanford.edu/class/cs193p/cgi-bin/drupal/system/files/sample_code/11-ThreadedFlickrTableView.zip

ImageLoadingOperation은 NSOperation의 서브 클래스입니다. Tableview 셀이 새 이미지를 요청하면 대기열에 URL을 추가하고 백그라운드 스레드의 로컬 NSDictionary에 다운로드됩니다. 다운로드 할 때 performSelectorOnMainThread를 사용하여 이미지를 가져 오는 주 스레드에서 tableview를 다시로드합니다.

는 도움이되기를 바랍니다.

+0

어디서 참조를 찾았습니까? URL이 – lifemoveson

+0

입니다. 논리를 시도합니다 !! – lifemoveson