2011-06-22 4 views
1

私のアプリケーションではテーブルビューがあり、テーブルビューの最初の行に4画像ビューを追加しています。次に画像ビューを次の行に追加します。画像ビューをテーブルビューの次の行に追加する

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    UITableViewCell *cell = nil; 
    static NSString *AutoCompleteRowIdentifier = @"AutoCompleteRowIdentifier"; 
    cell = [tableView dequeueReusableCellWithIdentifier:AutoCompleteRowIdentifier]; 

    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:AutoCompleteRowIdentifier] autorelease]; 

     UIImageView * imageView1 = [[[UIImageView alloc] initWithFrame:CGRectMake(25, 4, 80, 80)] autorelease]; 
     UIImageView * imageView2 = [[[UIImageView alloc] initWithFrame:CGRectMake(115,4,80, 80)] autorelease]; 
     UIImageView * imageView3 = [[[UIImageView alloc] initWithFrame:CGRectMake(205,4, 80, 80)] autorelease]; 
     UIImageView * imageView4 = [[[UIImageView alloc] initWithFrame:CGRectMake(295,4, 80, 80)] autorelease]; 
     UIImageView * imageView5 = [[[UIImageView alloc] initWithFrame:CGRectMake(25, 4, 80, 80)] autorelease]; 
     UIImageView * imageView6 = [[[UIImageView alloc] initWithFrame:CGRectMake(115,4,80, 80)] autorelease]; 

     int j=0; 
     imageView1.tag = j; 
     imageView2.tag = j+1; 
     imageView3.tag = j+2; 
     imageView4.tag = j+3; 
     imageView5.tag = j+4; 
     imageView6.tag = j+5; 

     [cell.contentView addSubview:imageView1]; 
     [cell.contentView addSubview:imageView2]; 
     [cell.contentView addSubview:imageView3]; 
     [cell.contentView addSubview:imageView4]; 
     [cell.contentView addSubview:imageView5]; 
     [cell.contentView addSubview:imageView6]; 
} 

for (int i = 1; i <= j; i++) { 
    imageView = (UIImageView *)[cell.contentView viewWithTag:i]; 
    imageView.image = nil; 
} 

int photosInRow; 

if ((indexPath.row < [tableView numberOfRowsInSection:indexPath.section] - 1) || ([sentence count] % 4 == 0)) { 
    photosInRow = 4; 
} else { 
    photosInRow = [sentence count] % 4; 
} 

for (int i = 1; i <=[sentence count]; i++){ 
    imageView = (UIImageView *)[cell.contentView viewWithTag:i]; 
    [self setImage1:imageView]; 
} 

    return cell; 
} 

私はムーImageViewの5と6はそれを行うには、次row.Please help.Howになりたい私は - :?私は、既存のコードにhelp.Iは、コードの私の部分を掲示していてくださいことをやります私の頭を壁に突きつけてこれを探していた。

あなたが怒鳴るようないくつかのことを試すことができますおかげで、 クリスティ

答えて

1

...あなたは基本的にあなたの必要なロジックを構築し、その後現在の行番号を確認...

UITableViewCell *cell = nil; 
static NSString *AutoCompleteRowIdentifier = @"AutoCompleteRowIdentifier"; 
cell = [tableView dequeueReusableCellWithIdentifier:AutoCompleteRowIdentifier]; 
if (cell == nil) 
{ 
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:AutoCompleteRowIdentifier] autorelease]; 
} 

int j=0; imageView1.tag = j; 


if(0 == [indexPath row]) 
{ 
UIImageView * imageView1 = [[[UIImageView alloc] initWithFrame:CGRectMake(25, 4, 80, 80)] autorelease]; 

UIImageView * imageView2 = [[[UIImageView alloc] initWithFrame:CGRectMake(115,4,80, 80)] autorelease]; 

UIImageView * imageView3 = [[[UIImageView alloc] initWithFrame:CGRectMake(205,4, 80, 80)] autorelease]; 

UIImageView * imageView4 = [[[UIImageView alloc] initWithFrame:CGRectMake(295,4, 80, 80)] autorelease]; 


imageView2.tag = j+1; 

imageView3.tag = j+2; 

imageView4.tag = j+3; 

    [cell.contentView addSubview:imageView1]; 

      [cell.contentView addSubview:imageView2]; 

      [cell.contentView addSubview:imageView3]; 

      [cell.contentView addSubview:imageView4]; 



}else if(0 == [indexPath row]) 
{ 
UIImageView * imageView5 = [[[UIImageView alloc] initWithFrame:CGRectMake(25, 4, 80, 80)] autorelease]; 

UIImageView * imageView6 = [[[UIImageView alloc] initWithFrame:CGRectMake(115,4,80, 80)] autorelease]; 


imageView5.tag = j+1; 

imageView6.tag = j+2; 



      [cell.contentView addSubview: imageView5]; 

      [cell.contentView addSubview:imageView6]; 


} 

    for (int i = 1; i <= j; i++) { 
    imageView = (UIImageView *)[cell.contentView viewWithTag:i]; 

    imageView.image = nil; 

} 
関連する問題