0

私は多くの問題に直面しています..私はios開発に慣れていないので、助けていただければ幸いです。

動的画像ビュー 問題1

カスタムセルの黄色と青の画像の上にN個の画像ビュー+ラベルを表示したい。

すべての行に表示される画像ビューの数を解析する必要があり、それに応じて、カスタムセルのすべての画像ビューに画像を割り当てる必要があります。どうやってやるの?データベースから画像リンクを取得して配列に保存しますが、特定の画像ビューにリンクを連続して適用するにはどうすればよいですか。

iOS のユーザー インターフェイスの上に構築するためのヒントが必要です。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 {
static NSString *CellIdentifierLeft = @"lefthand";
static NSString *CellIdentifierRight = @"righthand";

if (indexPath.row % 2 == 1) // to get two custom cell vice versa.
{
  LeftCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifierLeft];


    if (LeftCell == nil)
   { 
        LeftCell = [[customCellLeft alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifierLeft row:indexPath.row];


         LeftCell.scrollView  = [[cellScrollViewClass alloc] initWithFrame:CGRectMake(0,14,1024,187)];


    }
      LeftCell.videoImageView1.tag=[ImageLinkArray objectAtIndex:indexPath.row];
       LeftCell.label1.text=[TitleArray objectAtIndex:indexPath.row];

    return LeftCell;
}
  else
{

RightCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifierRight];


if(RightCell == nil)
{

    RightCell =[[customCellRight alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifierRight];

   RightCell.scrollView  = [[cellScrollViewClass alloc] initWithFrame:CGRectMake(0,14,1024,187)];


    }
      RightCell.videoImageView1.tag=[ImageLinkArray objectAtIndex:indexPath.row];
       RightCell.label1.text=[TitleArray objectAtIndex:indexPath.row];

    return RightCell;
}

カスタム セル クラス コード...

    - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier row:(int)row
 {
   self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
   if (self) {

    int indexNumber; // variable to store Array index number

    int VideoNumber=3; // imageview in particular cell + Train Engine.


   scrollView  = [[cellScrollViewClass alloc] initWithFrame:CGRectMake(33,14,958,187)]; // Scrollview 
    scrollView.scrollEnabled=YES;
    scrollView.userInteractionEnabled=YES;
    scrollView.showsHorizontalScrollIndicator=NO;
    scrollView.contentSize = CGSizeMake((335*VideoNumber),187); // To make ContentSize for item to scroll
      for (int i = 0; i < VideoNumber; i++)
    { // for loop to add 2 wagon view and 1 engine view on Left hand side Custom cell.

        if(i==0) // to check first item must be train Engine
        {
            CGRect frame;
            frame.origin.x = 0;
            frame.origin.y = 18;
            frame.size.width=186;
            frame.size.height= 162;

            UIView *EngineView = [[UIView alloc]initWithFrame:frame];
            UIImageView *engineImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 6, 186, 162)];
            UIImage *Image = [UIImage imageNamed:@"loco_left.png"];
            engineImageView.image = Image;
            [EngineView addSubview:engineImageView];
            [scrollView addSubview:EngineView];  // add 1st imageview that is Train Engine to first of scrollview
        }
        else

        { // else it must be wagon of train.

            indexNumber=row*(VideoNumber-1)+(i-1);// to get Index Number of array to to display Images as per cell number

            NSLog(@"at Normal row index number is %d",indexNumber);
            CGRect frame;
            frame.origin.x = (385*i)-432;
            frame.origin.y = 18;
            frame.size.width=385;
            frame.size.height= 163;

            UIView *wagon = [[UIView alloc]initWithFrame:frame];
            UIImageView *wagonImage = [[UIImageView alloc]initWithFrame:CGRectMake(230, 6, 385, 163)];
            UIImage *Image = [UIImage imageNamed:@"wagon_left.png"];
            wagonImage.image = Image;
            [wagon addSubview:wagonImage];


            UIView *videoviewContainer = [[UIView alloc]initWithFrame:CGRectMake(15, 30, 190 , 200)];

            videoImageView2 = [[UIImageView alloc]initWithFrame:CGRectMake(0,0, 190, 100)];
            UIImage *bgImage = [UIImage imageNamed:@"video.png"];
            videoImageView2.image = bgImage;
            videoviewContainer.contentMode = UIViewContentModeLeft; // set Video Image view to left hand side of wagon UIView
            videoImageView2.tag=indexNumber;

            [videoviewContainer addSubview:videoImageView2];

            UITapGestureRecognizer *video = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(VideoItemOne:)];
            [videoImageView2 addGestureRecognizer:video];



            [videoImageView2 setMultipleTouchEnabled:YES];
            [videoImageView2 setUserInteractionEnabled:YES];

            UIView *textUiView = [[UIView alloc]initWithFrame:CGRectMake(208,28, 150 , 187)];
            textUiView.contentMode = UIViewContentModeRight;
            label2 = [[UILabel alloc]initWithFrame:CGRectMake(28,10, 150 , 87)];
            label2.text=[TitleArray objectAtIndex:indexNumber];
            label2.backgroundColor = [UIColor clearColor];
            label2.textColor=[UIColor redColor];
            label2.numberOfLines = 4;
            [textUiView addSubview:label2];

            [wagonImage addSubview:textUiView];
            [wagonImage addSubview:videoviewContainer];

            [scrollView addSubview:wagon];

        }
    }


    [self.contentView addSubview:scrollView];
     }
return self;
  }
-(void)populateWithImage:myImage andText:myText
{
[videoImageView2 setImageWithURL:[NSURL URLWithString:myImage]
                placeholderImage:[UIImage imageNamed:@"video.png"]];
  }
4

1 に答える 1

0

カスタムセルには次のものが必要です: (より良い命名規則を使用する必要があることに注意してください。私は例を示しているだけです)

  • 背景画像ビュー (bgImage)
  • メイン画像ビュー (mainImage)
  • UI ラベル (mainLabel)

このセルの init で、indexpath.row に基づいて、左または右のトレイン イメージを割り当てます。

また、主画像ビューのフレームとラベルを設定します。

        MYCustomCell * cell;

        if(indexPath.row %2)
        {
        cell = [tableView dequeueReusableCellWithIdentifier:"OddCell"];
            if (cell == nil)
             { 
                cell = [[MYCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifierLeft row:indexPath.row];
             }
        }
        else {
             cell = [tableView dequeueReusableCellWithIdentifier:"EvenCell"];
            if (cell == nil)
             { 
                cell = [[MYCustomCell alloc] initWithStyle:UITableViewCellStyleDefault  reuseIdentifier:CellIdentifierLeft row:indexPath.row];
             }
        }


    [cell populateWithImage:myImage andText:myText]; //myImage and myText are to be gotten from the data source which in your case is ImageLinkArray and TitleArray
return cell;
于 2013-05-23T12:17:42.670 に答える