셀에 이미지를 표시하는 방법?
-
19-09-2019 - |
문제
나는 iPhone Development를 처음 사용하고 있으며 각 셀에 이미지를 표시하고 싶습니다. 배열에 이미지의 URL 만 가지고 있습니다.
해결책
//put this code in cellForRowAtIndexPath.... I'm assuming you have an array of url's that point to images
id urlPath = [yourArray objectAtIndex:indexOfImage];
NSURL *url = [NSURL URLWithString:urlPath];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:data];
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
//insert an image into your cell
cell.imageView = image;
더 효율적인 방법이있을 수 있지만 TableView 셀을 사용자 정의하기 시작하는 괜찮은 방법입니다. ImageView는 UitableViewCell 클래스의 많은 속성 중 하나입니다.
추가 독서 .... UitableViewCell 클래스 참조
다른 팁
이 Apple의 샘플 코드를 살펴 봐야합니다. 훌륭하고 필요한 것을 구현하는 방법과 다른 유용한 것들을 보여줍니다.고급 테이블보기 셀
제휴하지 않습니다 StackOverflow