实际上,苹果公司的人似乎并没有真正让 uitableviewcell 像普通开发人员希望的那样可定制。
所以你必须自己定制它。并且因为我没有时间覆盖 UITableViewCell 并实现我的自定义。
我已经匆匆忙忙地做了。通过
UITableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:@"cell"];
if( nil == cell ) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"] autorelease];
//contentview
UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(1, 5, 11, 9)];
imageView.image=_headerImage;
UILabel* textLabel=[UILabel new];
UILabel* detailTextLabel=[UILabel new];
//get and set the size of the labels here
textLabel.font=_font;
detailTextLabel.font=_fontD;
textLabel.numberOfLines=0;
detailTextLabel.numberOfLines=0;
textLabel.backgroundColor=[UIColor clearColor];
detailTextLabel.backgroundColor=[UIColor clearColor];
textLabel.tag=202;
detailTextLabel.tag=203;
imageView.tag = 204;
[cell.contentView addSubview:imageView];
[cell.contentView addSubview:textLabel];
[cell.contentView addSubview:detailTextLabel];
[textLabel release];
[detailTextLabel release];
[imageView release];
}
当然在实施时
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(!_cellTitleSizes)
{
_cellTitleSizes= [NSMutableArray new];
_cellDetailSizes= [NSMutableArray new];
}
MenuItem *tempItem =[self GetItemFromIndexPath:indexPath];
CGSize size = [ tempItem.title sizeWithFont:_font constrainedToSize:_textSize lineBreakMode:UILineBreakModeWordWrap];
CGSize size2 = [[MenuListViewController GetDetailsToDisplay:tempItem] sizeWithFont:_fontD constrainedToSize:_textSize lineBreakMode:UILineBreakModeWordWrap];
//the following information will be used to set the title and description labels in the cell.
[_cellTitleSizes addObject:[NSValue valueWithCGSize:size]];
[_cellDetailSizes addObject:[NSValue valueWithCGSize:size2]];
return MAX( (size.height+size2.height)+ 30, 44.0f );
}
祝大家好运