이미지 URL을 사용하여 UITableViewCell에 이미지를 설정하고 있지만 UITableView를 스크롤하지 않으면 이미지가로드되지 않습니다. 사용중인 코드는 대략 알고 있어야합니다. SDWeb 이미지 라이브러리에서 URL에서 이미지를 다운로드 할 수 있지만, 나는 어떤 라이브러리를 사용하고 싶지 않습니다. 무엇을 목표로 잘못했는지 말해주십시오.iOS의 URL에서 UITableview 셀 이미지 설정
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
NSDictionary *dictCard=[cardsDetailsArray objectAtIndex:indexPath.row];
UILabel *nameLabel = (UILabel *)[cell viewWithTag:10];
UILabel *dateLabel = (UILabel *)[cell viewWithTag:11];
UIImageView *cellImage=(UIImageView *)[cell viewWithTag:0];
CGSize firstSize=CGSizeZero;
if([[dictCard objectForKey:@"orientation"]isEqualToString:@"1"]){
[cellImage setFrame:CGRectMake(0, 0, 75, 68)];
firstSize=CGSizeMake(75,68);
}
if([[dictCard objectForKey:@"orientation"]isEqualToString:@"0"]){
[cellImage setFrame:CGRectMake(0, 0, 107, 72)];
firstSize=CGSizeMake(107,72);
}
[cellImage setBackgroundColor:[UIColor clearColor]];
NSString *string=[dictCard objectForKey:@"email_sent"];
NSArray *items = [string componentsSeparatedByString:@","];
dateLabel.text=[dictCard objectForKey:@"date"];
nameLabel.text=[NSString stringWithFormat:@"Sent to %d People",[items count]];
NSURL* url = [NSURL URLWithString:(NSString *) [dictCard objectForKey:@"card_thumbnail"]];
NSURLRequest* request = [NSURLRequest requestWithURL:url];
[NSURLConnection sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse * response,
NSData * data,
NSError * error) {
if (!error){
UIImage* image = [[UIImage alloc] initWithData:data];
//i am scaling the image here
UIImage *imageScale=[self imageWithImage:image scaledToSize:firstSize];
[cellImage setImage:imageScale];
}
}];
return cell;
}
I도 [__tableViewDraft reloadData]에 추가 한 상기 셀의 이미지를 설정 한 후하지만 이에 내 셀의 셀 이미지 변경에 유지한다.
me.Thanks에 대한 이해를 돕기 위해 코드를 수정 해 주실 수 있습니까? – ankyy