0
我有三個以編程方式配置的行。我只想在表格視圖的第一行放置圖片。圖像具有覆蓋整個第一行(而不是在左側表格視圖單元格的默認值)將圖像放在表格視圖上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;
}
}
@saadnib:如果我要使用uiimageView我得到exception..code.NSString * imagefile = [[NSBundle mainBundle] pathForResource:@「guitar」ofType:@「jpg」]; \t \t \t \t \t \t \t \t \t \t的UIImageView * LI = [[ALLOC的UIImageView] initWithContentsOfFile:鏡像文件]。 \t \t \t \t \t [cell.contentView addSubview:li]; – kingston 2011-04-20 07:24:25
由於使用錯誤的方式,您收到錯誤信息 – saadnib 2011-04-20 07:39:52
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 release]; – saadnib 2011-04-20 07:41:59