iPhone App2011.09.19 10:55

이렇게 커스텀 셀을 만든후


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

BoardCustomCell *cell = (BoardCustomCell *)[tableView dequeueReusableCellWithIdentifier:BoardCustomCellIdentifier];

  

// NSUInteger row = indexPath.row;

  

if(cell == nil)

{

cell = [BoardCustomCell cellWithNib];

}

  

NSMutableDictionary* commentData = [commentDataArray objectAtIndex:indexPath.row];

cell.contentLabel.text = [commentData objectForKey:@"CmtContent"];

cell.memberNameLabel.text = [commentData objectForKey:@"MemberName"];

cell.dateLabel.text = [commentData objectForKey:@"CreateDate"];

cell.memberLevelLabel.text = [commentData objectForKey:@"PntSumLv"];

cell.memberPointLabel.text = [commentData objectForKey:@"ReCmdCount"];

  

//image 나중에 주소를 plist 넣자

NSString* imageUrl= [NSString stringWithFormat:@"http://주소/%@",[commentData objectForKey:@"MemberPhoto"]];

  

if ([commentData objectForKey:@"MemberPhoto"] == nil)

{

imageUrl= [NSString stringWithFormat:@"http://주소/default_profileImg_small.gif"];

}

  

// UIImage* memberPhotoImage= [[UIImage alloc]initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imageUrl]]];

// UIImage* memberPhotoImage= [[UIImage alloc]initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imageUrl]]];

  

[cell performSelectorInBackground:@selector(setImageUrl:) withObject:imageUrl];

// NSURL *url = [NSURL URLWithString:imageUrl];

// NSData *data = [NSData dataWithContentsOfURL:url];

// UIImage *memberPhotoImage = [[UIImage alloc] initWithData:data];

//

// [cell.memberPhotoImage setImage:memberPhotoImage];

// [memberPhotoImage release];

  

return cell;

}


주석 처리한 부분으로 이미지를 처리 했는데 느려서

[cell performSelectorInBackground:@selector(setImageUrl:) withObject:imageUrl];

이렇게 cell에서 이미지 처리를 백그라운드로 돌렸다.

cell 에서 구현한 소스는 이렇다.

-(void) setImageUrl:(NSString *)urlString

{

NSAutoreleasePool* pool = [NSAutoreleasePool new];

  

NSURL *url = [NSURL URLWithString:urlString];

NSData *data = [NSData dataWithContentsOfURL:url];

UIImage *img = [[[UIImage alloc] initWithData:data] autorelease];

  

[self.memberPhotoImage setImage:img];

[pool release];

}

Posted by 동동(이재동)