2011-04-20 11 views
0

私はプログラムで設定された3つの行を持っています。私は、テーブルビューの最初の行にのみイメージを配置したい。テーブルビューに画像を置くiphone

- (CGFloat)tableView:(UITableView *)aTableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
switch (indexPath.row) 
{ 
    case 1: 

if(indexPath.row==1) 
    { 
    return 230.0; // first row is 123px high 
    } 
     default: 
      return 100.0; // all other rows are 40px high 
    } 
} 
-(void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath 
{ 
    switch (indexPath.row) { 

      case 0: 
      break;  

     case 1: 
      if (indexPath.row==1) { 

       UIButton *button1=[UIButton buttonWithType:UIButtonTypeRoundedRect]; 
       [button1 setFrame:CGRectMake(5, 10, 310, 40)]; 
       [button1 setTitle:@"Give" forState:UIControlStateNormal]; 
       [button1 addTarget:self action:@selector(give) 
       forControlEvents:UIControlEventTouchUpInside]; 

       [button1.titleLabel setFont:[UIFont boldSystemFontOfSize:15]]; 
       [button1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 
       [cell.contentView addSubview:button1]; 



       UIButton *button2=[UIButton buttonWithType:UIButtonTypeRoundedRect]; 
       [button2 setFrame:CGRectMake(5, 60, 310, 40)]; 
       [button2 setTitle:@"YouTube" forState:UIControlStateNormal]; 
       [button2 addTarget:self action:@selector(Announcements) 
       forControlEvents:UIControlEventTouchUpInside]; 

       [button2.titleLabel setFont:[UIFont boldSystemFontOfSize:15]]; 
       [button2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 
       [cell.contentView addSubview:button2]; 


       UIButton *button3=[UIButton buttonWithType:UIButtonTypeRoundedRect]; 
       [button3 setFrame:CGRectMake(5, 110, 310, 40)]; 
       [button3 setTitle:@"Follow us on Twitter" forState:UIControlStateNormal]; 
       [button3 addTarget:self action:@selector(Twitter) 
       forControlEvents:UIControlEventTouchUpInside]; 

       [button3.titleLabel setFont:[UIFont boldSystemFontOfSize:15]]; 
       [button3 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 
       [cell.contentView addSubview:button3]; 

       UIButton *button4=[UIButton buttonWithType:UIButtonTypeRoundedRect]; 
       [button4 setFrame:CGRectMake(5, 160, 310, 40)]; 
       [button4 setTitle:@"Follow us on FaceBook" forState:UIControlStateNormal]; 
       [button4 addTarget:self action:@selector(Facebook) 
       forControlEvents:UIControlEventTouchUpInside]; 

       [button4.titleLabel setFont:[UIFont boldSystemFontOfSize:15]]; 
       [button4 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 

       [cell.contentView addSubview:button4]; 

       /*[button1 release]; 
       [button2 release]; 
       [button3 release]; 
       [button4 release];*/ 

      } 
      break; 
     default: 
      break; 
    } 
    } 

答えて

2

あなたのcontentviewにUIImageViewを追加することができます。画像は

はここに私のコードです(ないデフォルトでは、テーブルビューのセルの左側に)全体の最初の行をカバーしています。

+0

@saadnib:もし私がuiimageViewを使用するのであれば、例外が発生します。code.NSString * imagefile = [[NSBundle mainBundle] pathForResource:@ "guitar" ofType:@ "jpg"]; \t \t \t \t \t \t \t \t \t \t UIImageViewの*李= [[UIImageView ALLOC] initWithContentsOfFile:画像ファイル]。 \t \t \t \t \t [cell.contentView addSubview:li]; – kingston

+0

あなたが間違った方法で使用しているためにエラーが発生しています – saadnib

+0

UIImageView * imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f、0.0f、320.0f、50.0f)]; \t [imgView setImage:[UIImage imageNamed:@ "guitar.jpg"]]; \t [cell.contentView addSubview:imgView]; \t [imgViewリリース]; – saadnib

関連する問題