編寫代碼以創建自定義UITableViewCell
(動態)。你不會得到這個問題。
嘗試使用下面的示例代碼;
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];
}
UIImageView *cellImageView1=[[UIImageView alloc]initWithFrame:CGRectMake(0,0,320,80)];
UIImage *cellImage1=[UIImage imageNamed:@"table_bar.png"];
cellImageView1.image=cellImage1;
cell.backgroundView=cellImageView1;
NSString *projectName = [projectNameArray objectAtIndex:indexPath.row];
cell.imageView.image=[self returnImage:projectName];
cell.imageView.frame=CGRectMake(10, 05, 40, 40);
cell.imageView.image=[self returnImage:projectName];
UILabel *cellLabel=[[UILabel alloc] initWithFrame:CGRectMake(75, 15, 150, 30)];
cellLabel.text=projectName;
cellLabel.backgroundColor=[UIColor clearColor];
cellLabel.textAlignment = UITextAlignmentLeft;
cellLabel.tag = 4444;
[cell.contentView addSubview:cellLabel];
[cellLabel release];
cell.accessoryView =(UIButton*) [buttonArray objectAtIndex:indexPath.row];
return cell;
我希望它能幫助你。