2012-03-26 5 views
0

UITableViewCell에서 비동기 적으로 서버에서로드 UIImages를 시도합니다. 내 코드는 시뮬레이터에서는 정상적으로 작동하지만 장치에서는 제대로 작동하지 않습니다. 내 코드는 다음과 같이, 시뮬레이터UIImage가 제대로 작동하지 않습니까?

- (UITableViewCell *)tableView:(UITableView *)tableView 
    cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
IScopeCustomTableCell *cell = (IScopeCustomTableCell *)[tableView dequeueReusableCellWithIdentifier:CellClassName]; 

if (!cell){ 
    NSArray *topLevelItems = [cellLoader instantiateWithOwner:self options:nil]; 
    cell = [topLevelItems objectAtIndex:0]; 
} 

cell.delegate = self; 
cell.videoTitle.text = [[videoDataArray objectAtIndex:indexPath.row] objectForKey:@"VideoTitle"]; 
cell.videoLink = [[videoDataArray objectAtIndex:indexPath.row] objectForKey:@"VideoLink"]; 
cell.videoThumbnailImageLink = [[videoDataArray objectAtIndex:indexPath.row] objectForKey:@"VideoThumbnail"]; 
cell.videoThumbnail.tag = indexPath.row; 
cell.tag = indexPath.row; 
[cell.activityIndicator startAnimating]; 
NSInvocationOperation *operation = [[NSInvocationOperation alloc] 
            initWithTarget:self 
            selector:@selector(loadImage:) 
            object:cell]; 
[queue addOperation:operation]; 
return cell; 
} 

- (void)loadImage:(IScopeCustomTableCell *)cell { 
NSLog(@"Image link :- %@", cell.videoThumbnailImageLink); 

//NSData* imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:cell.videoThumbnailImageLink]]; 
NSData* imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:cell.videoThumbnailImageLink]]; 
UIImage* image = [UIImage imageWithData:imageData]; 

cell.videoThumbnail.image = image; 
[cell.activityIndicator stopAnimating]; 
[cell.activityIndicator removeFromSuperview]; 

//[self performSelectorOnMainThread:@selector(displayImage:) withObject:image waitUntilDone:NO]; 
} 

상기 코드 미세하지만 장치에 becoz,있는 UIImage * 화상을 NSData loadImage GET 방법이 적절한 데이터를 포함하더라도의 (0X0) 널.

+0

얼마나 많은 파일 크기가 서버에서 왔습니까 ??? – parag

+0

@paragkavar, 20KB – Tirth

+0

명백한 진술에 대해 사과 드려 죄송 합니다만, 기기가 웹에 액세스 할 수 있는지 이미 확인 했습니까? 또한 셀이 표시 될 때마다 스레드를 실행하는 것이 최선의 방법은 아닙니다. 비동기 적으로 이미지를로드하기 위해 웹에서 많은 자습서를 찾을 수 있습니다. – Leonardo

답변

0

내가이 포함 된이 링크 마법사 코드가 제대로 작동하고 정확하게 작동합니다.

https://github.com/jakemarsh/JMImageCache

+0

http://maniacdev.com/2012/04/best-resources-in-ios-development- 2012 년 4 월 2 일 /? utm_source = 피드 버너 및 utm_medium = 피드 및 utm_campaign = 피드 % 3A + maniacdev + % 28iPhone % 2C + iOS + 4 % 2C + iPad + SDK + 개발 + 자습서 + 및 + 프로그래밍 + 팁 % 29 – Tirth

+0

http : // gameit .ro/tag/cocos2d-x / – Tirth

0

많은 자동 접기 개체가 만들어지고 앱 크기가 커지고 또한 operation을 공개하지 않으므로 최선을 다하고 있지 않습니다. 먼저 operation을 출시 한 후 이 문제를 정렬 희망 [queue addOperation:operation];

대신에 이미지 데이터를 얻고 이미지에 저장이 코드를 사용 ...

NSData* data = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:cell.videoThumbnailImageLink]]]; 
UIImage* img = [[UIImage alloc] initWithData:data]; 
[data release]; 
cell.videoThumbnail.image = image; 
[img release]; 

..

+0

내 친구 나는 이미 이것을 시도했지만 나를 위해 일하지 않았습니다 .... – Tirth

관련 문제