[英]Custom tableview cell with 6 imageviews
I have a very difficult problem. 我有一个非常困难的问题。 This is how my custom cell looks like. 这是我的自定义单元格的样子。
|--------------------------------------------------------------------------|
| |
| |
| Imageview1 Imageview2 Imageview3 Imageview4 imageview5 |
| |
| |
| |
|--------------------------------------------------------------------------|
I have a core database with 20 images. 我有一个包含20张图像的核心数据库。 What I want to do is to fill up all these imageviews with my images. 我要做的是用我的图像填充所有这些图像视图。 So at the and I should have 5 rows with in each imageview a different image. 因此,在和我应该有5行,每个imageview中有一个不同的图像。
Here is my code for my cellforrowAtIndexpath 这是我的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;
}
This is how far i got. 这就是我走了多远。 I don't now how to fill up this tableview correctly. 我现在不正确地填充此tableview。 The other imageviews are name img_Player2,img_Player3,img_Player4,img_Player5. 其他图像视图是名称img_Player2,img_Player3,img_Player4,img_Player5。
Can anybody help? 有人可以帮忙吗?
Thank you 谢谢
SCREENS WITH WHAT I WANT TO ACHIEVE 我要实现的屏幕截图
You need to add the UIImageViews
to the contentView
of the UITableViewCell
. 您需要将UIImageViews
添加到UITableViewCell
的contentView
中。 Let's assume your 5 images are loaded in an NSArray
called imagesArray
. 假设您的5张图像已加载到名为imagesArray
的NSArray
。 For simplicity I'm assuming each of your images is 64 (320/5) pixels wide and 44 pixels high. 为简单起见,我假设您的每个图像的宽度均为64(320/5)像素,高度为44像素。
Your code inside cellForRowAtIndexPath
should roughly look like this: 您的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;
}
Your code will be this: 您的代码将如下所示:
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.