好的,事情是这样的,现在已经有两天的时间试图建立一个具有字幕样式的像样的表格视图单元格了。
所以我重写了'tableview:heightforrowatindex:‘方法。好的,我也把详细信息的行数设为0。
这在ios4.0中运行良好。
但对于iOS3.0,看起来文本标签和详细文本标签在顶部有一定的边距,这会将所有单元格内容向下推到与下面的单元格重叠。这是疯狂的行为。而且我找不到一种方法在它的内容视图中设置textlabel/detailtextlabel的位置。
请帮帮忙。Resizing UITableViewCells in iOS4 versus iOS3这家伙说他要实现他自己的控制。但这工作太多了,对我来说也很难。一定有人已经知道有一种方法可以绕过这个问题。谢谢
发布于 2011-02-28 19:24:21
实际上,苹果的员工似乎并没有像普通开发者希望的那样让uitableviewcell变得可定制化。
所以你必须自己定制它。因为我没有时间覆盖UITableViewCell并实现我的自定义and。
我做得很匆忙。通过
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 );
}祝你们大家好运
https://stackoverflow.com/questions/5116026
复制相似问题