[英]Custom tableview cell with 6 imageviews
我有一个非常困难的问题。 这是我的自定义单元格的样子。
|--------------------------------------------------------------------------|
| |
| |
| Imageview1 Imageview2 Imageview3 Imageview4 imageview5 |
| |
| |
| |
|--------------------------------------------------------------------------|
我有一个包含20张图像的核心数据库。 我要做的是用我的图像填充所有这些图像视图。 因此,在和我应该有5行,每个imageview中有一个不同的图像。
这是我的cellforrowAtIndexpath的代码
- (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];
}
for(int i=0;i<5;i++)
{
float xCoord = 0.0;
Team *team = [self.fetchedResultsController objectAtIndexPath:indexPath];
NSData* imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:team.image]];
UIImage* image = [[UIImage alloc] initWithData:imageData];
UIImageView* imgView = [[UIImageView alloc] initWithImage:image];
[imgView setFrame:CGRectMake(xCoord,0,imgView.frame.size.width, imgView.frame.size.height)];
[cell.contentView addSubview:imgView];
xCoord += imgView.frame.size.width;
}
return cell;
}
这就是我走了多远。 我现在不正确地填充此tableview。 其他图像视图是名称img_Player2,img_Player3,img_Player4,img_Player5。
有人可以帮忙吗?
谢谢
我要实现的屏幕截图
这是我要实现的目标:
现在我有这个 。
您需要将UIImageViews
添加到UITableViewCell
的contentView
中。 假设您的5张图像已加载到名为imagesArray
的NSArray
。 为简单起见,我假设您的每个图像的宽度均为64(320/5)像素,高度为44像素。
您的cellForRowAtIndexPath
内部的代码应大致如下所示:
float xCoord = 0.0;
for (UIImageView *imgView in imagesArray)
{
[imgView setFrame:CGRectMake(xCoord,0,imgView.frame.size.width, imgView.frame.size.height)];
[cell.contentView addSubview:imgView];
xCoord += imgView.frame.size.width;
}
您的代码将如下所示:
float xCoord = 0.0;
for(int i=0;i<5;i++)
{
Team *team = [self.fetchedResultsController objectAtIndexPath:indexPath];
NSData* imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:team.image]];
UIImageView* imgView = [[UIImageView alloc] initWithImage:[UIImage imageWithData:imageData]];
[imgView setFrame:CGRectMake(xCoord,0,imgView.frame.size.width, imgView.frame.size.height)];
[cell.contentView addSubview:imgView];
xCoord += imgView.frame.size.width;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.