1
我打算將圖像(通過URL字符串)添加到表格視圖中。但是,照片圖像不會顯示在表格中。以下是我的代碼。自定義表格單元格以顯示圖像
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectZero];
imageView.tag = kImageValueTag;
[cell.contentView addSubview:imageView];
[imageView release];
}
// Configure the cell...
NSUInteger row = [indexPath row];
Photo *thisPhoto = [self.thisArray objectAtIndex:row];
UIImageView *thisImageView = (UIImageView *)[cell.contentView viewWithTag:kImageValueTag];
NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: thisPhoto.imageURL]];
NSLog(@"URL: %@",thisPhoto.imageURL);
thisImageView.image = [UIImage imageWithData:imageData];
return cell;
}
我的所有圖片都是不同的大小。我如何讓表格根據其尺寸顯示圖像?
你知道嗎?如果我有2張圖片需要在單個單元格中加載,是否可以實現MHLazyTableImages中的代碼? – Zhen 2011-05-31 02:40:41