2012-05-12 26 views
0

私はUIImageViewを単一のUITableViewセルに追加するのに本当に問題があります。私のストーリーボードには、UITableViewControllerと4つのプロトタイプダイナミックセルがあります。それらのうち3つは、通常の左詳細セルと同じくらいうまく機能し、正常に動作します。しかし、そのうちの1つはUIImageViewを持つ必要があります。UITableViewCellにUIImageViewを追加しますか?

私はビュービューにセルを追加しました。セルにはプロパティを持つカスタムクラスが与えられているので、イメージビューにアクセスできます。

私には次のセルがあります。 タイトルセル。 イメージセル。 URLセル。 メモセル。

テーブルビューの内容は、ユーザーがURL、メモまたは画像を追加するかどうかによって変わります。したがって、ユーザーは常にタイトルセルを他のセルの1つと見なします。

ここに私のコードがありますが、私はちょうどそのイメージセルに表示するUIImageViewを得ることができません。あなたは何が間違って、おかげで参照してくださいことを願っています。

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

    static NSString *CellIdentifier = @"Cell"; 

    //0 = Image 
    if ([[NSUserDefaults standardUserDefaults] integerForKey:@"NewScrapbookEntry"] == 0) 
    { 
     if (indexPath.row == 0) CellIdentifier = @"titleCell"; 
     if (indexPath.row == 1) CellIdentifier = @"imageCell"; 
     if (indexPath.row == 2) CellIdentifier = @"notesCell"; 
    } 
    //1 = URL 
    else if ([[NSUserDefaults standardUserDefaults] integerForKey:@"NewScrapbookEntry"] == 1) 
    { 
     if (indexPath.row == 0) CellIdentifier = @"titleCell"; 
     if (indexPath.row == 1) CellIdentifier = @"urlCell"; 
     if (indexPath.row == 2) CellIdentifier = @"notesCell"; 
    } 
    //2 = Notes 
    else if ([[NSUserDefaults standardUserDefaults] integerForKey:@"NewScrapbookEntry"] == 2) 
    { 
     if (indexPath.row == 0) CellIdentifier = @"titleCell"; 
     if (indexPath.row == 1) CellIdentifier = @"notesCell"; 
    } 

    ScrapbookImageDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) 
    { 
     cell = [[ScrapbookImageDetailCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier]; 
     cell.editingAccessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    } 

    [cell setBackgroundColor:[UIColor colorWithRed:250.0f/255.0f green:250.0f/255.0f blue:250.0f/255.0f alpha:1.0f]]; 
    [cell setSelectionStyle:UITableViewCellSelectionStyleGray]; 

    cell.textLabel.adjustsFontSizeToFitWidth = YES; 

    cell.textLabel.text = [firstSection objectAtIndex:indexPath.row]; 
    cell.detailTextLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:13.0f]; 
    cell.detailTextLabel.numberOfLines = 0; 
    cell.accessoryView = nil; 

    switch (indexPath.section) 
    { 
     case 0: 
      switch (indexPath.row) 
     { 
      case 0: 
      {     
       cell.detailTextLabel.text = scrapbook.title; 
      } 
       break; 

      case 1: 
      { 
       //0 = Image 
       if ([[NSUserDefaults standardUserDefaults] integerForKey:@"NewScrapbookEntry"] == 0) 
       { 
        cell.detailTextLabel.text = nil; 
        cell.iv.image = [UIImage imageNamed:@"image.png"]; 
       } 
       //1 = URL 
       else if ([[NSUserDefaults standardUserDefaults] integerForKey:@"NewScrapbookEntry"] == 1) 
       { 
        cell.detailTextLabel.text = scrapbook.url; 
       } 
       //2 = Notes 
       else if ([[NSUserDefaults standardUserDefaults] integerForKey:@"NewScrapbookEntry"] == 2) 
       { 
        cell.detailTextLabel.text = scrapbook.notes; 
       } 
      } 
      break; 

      case 2: 
      { 
       cell.detailTextLabel.text = scrapbook.notes; 
      } 
      break; 

      default: 
       break; 
     } 
     break; 

     default: 
      break; 
    } 

    return cell; 
} 

答えて

0

なぜ識別子の値を変更していますか?あなたがしなければならないことは、カスタムセルを作成し、行の高さで、それが希望の行であるかどうかをチェックし、行のメソッドのセルでnのイメージの高さを返します。他に追加してイメージビューを作成したくない場合

+0

あなたの言っていることが分かりますが、別のセル識別子を使用している理由は、私のストーリーボードにカスタムセルがあるため、特定の識別子indexPathは、ストーリーボードのそのセルを使用します。基本的には、私のカスタムセルを視覚的に簡単に作ることができます。 –

関連する問題