서버에서 가져온 NSData
의 이미지를로드하고 사용자 지정 UITableViewCell
에 표시하려고하는데 올바르게 작동하지 않고 이미지를 반복해서 반복하고 있습니다. 상단 NSData의 이미지가 올바르게로드되지 않음
indexPath.row = 0
있습니다. 셀이로드되면 다음 코드를 호출하여 이미지를로드합니다 (NSLog를 사용할 때 모든 이미지에 올바른 URL이 반환 됨) 올바른 이미지를 다운로드하는 것처럼 보입니다. 하지만합니다 (
NSData
서버에서 반환
- (void) startLoadingImage
{
NSString *url = @"myurlhere";
url = [url stringByAppendingFormat:identifier];
NSLog(@"Image URL: %@", url); //THIS IS WHERE I DETERMINE THAT IT IS DOWNLOADING THE CORRECT IMAGE
NSURLRequest * request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:url]];
NSURLConnection * imageConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[imageConnection start];
}
는 셀은 네 개의 이미지를로드까지 잘 작동
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
if (!rawData) rawData=[[NSMutableData alloc]initWithLength:0];
[rawData appendData:data];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"Image did finish loading. Displaying...");
[productImage setImage:[[UIImage alloc]initWithData:rawData]];
}
위임 방법을 ... 사용하고, 그것은 이미지를 반복 시작 이름과 가격 같은 셀의 정보가 올바르게 표시됩니다). 즉, 네 장마다 청바지 사진을 계속 볼 수 있습니다.
여기 내 결과는 NSLog
입니다. 다시 말하지만 모든 것이 정확하다고 보입니다. 보시
2012-02-21 14:45:01.152 APPNAME[7873:11f03] Image URL: http://www.MYAPPURL.net/production/img/[email protected]
2012-02-21 14:45:01.173 APPNAME[7873:11f03] Image URL: http://www.MYAPPURL.net/production/img/[email protected]
2012-02-21 14:45:01.199 APPNAME[7873:11f03] Image did finish loading. Displaying...
2012-02-21 14:45:01.205 APPNAME[7873:11f03] Image did finish loading. Displaying...
2012-02-21 14:45:11.064 APPNAME[7873:11f03] Image URL: http://www.MYAPPURL.net/production/img/[email protected]
2012-02-21 14:45:11.476 APPNAME[7873:11f03] Image did finish loading. Displaying...
2012-02-21 14:45:12.432 APPNAME[7873:11f03] Image URL: http://www.MYAPPURL.net/production/img/[email protected]
2012-02-21 14:45:12.751 APPNAME[7873:11f03] Image URL: http://www.MYAPPURL.net/production/img/[email protected]
2012-02-21 14:45:13.010 APPNAME[7873:11f03] Image did finish loading. Displaying...
2012-02-21 14:45:13.013 APPNAME[7873:11f03] Image did finish loading. Displaying...
2012-02-21 14:45:14.574 APPNAME[7873:11f03] Image URL: http://www.MYAPPURL.net/production/img/[email protected]
2012-02-21 14:45:14.948 APPNAME[7873:11f03] Image did finish loading. Displaying...
그래서, 이미지 84, 85, 86, 89, 80, 81 로딩하지만, 단지 이미지 84, 85, 86, 89을 표시하고, 그런 다음이를 반복한다.
왜 이런 일이 일어나는 이유는 무엇입니까?
마치 셀 재사용 문제처럼 보입니다. –
어떻게 수정하겠습니까? – Baub