0

私は非常に難しい問題を抱えています。これが私のカスタムセルの外観です。

|--------------------------------------------------------------------------|
|                                                                          |
|                                                                          |
|  Imageview1   Imageview2      Imageview3     Imageview4    imageview5    |
|                                                                          |
|                                                                          |
|                                                                          |                      
|--------------------------------------------------------------------------|

20 個の画像を含むコア データベースがあります。私がやりたいことは、これらすべてのイメージビューを私の画像で埋めることです。したがって、各イメージビューに異なるイメージを含む5行が必要です。

これが私の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;
}

これが私が得た距離です。このテーブルビューを正しく埋める方法がわかりません。他のイメージ ビューは、img_Player2、img_Player3、img_Player4、img_Player5 という名前です。

誰でも助けることができますか?

ありがとうございました

私が達成したいことを画面に表示

これは私が達成したいことです:

そして、現時点ではこれを持っています。

4

1 に答える 1

0

UIImageViewsの に を追加する必要がありcontentViewますUITableViewCellNSArray5 つの画像が呼び出された にロードされていると仮定しましょうimagesArray。簡単にするために、各画像は幅 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;
}
于 2012-10-09T19:42:12.980 に答える