首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iOS 3.0和UITableViewCell版的numberOfLines=0有什么问题?

iOS 3.0和UITableViewCell版的numberOfLines=0有什么问题?
EN

Stack Overflow用户
提问于 2011-02-25 18:17:42
回答 1查看 284关注 0票数 0

好的,事情是这样的,现在已经有两天的时间试图建立一个具有字幕样式的像样的表格视图单元格了。

所以我重写了'tableview:heightforrowatindex:‘方法。好的,我也把详细信息的行数设为0。

这在ios4.0中运行良好。

但对于iOS3.0,看起来文本标签和详细文本标签在顶部有一定的边距,这会将所有单元格内容向下推到与下面的单元格重叠。这是疯狂的行为。而且我找不到一种方法在它的内容视图中设置textlabel/detailtextlabel的位置。

请帮帮忙。Resizing UITableViewCells in iOS4 versus iOS3这家伙说他要实现他自己的控制。但这工作太多了,对我来说也很难。一定有人已经知道有一种方法可以绕过这个问题。谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-02-28 19:24:21

实际上,苹果的员工似乎并没有像普通开发者希望的那样让uitableviewcell变得可定制化。

所以你必须自己定制它。因为我没有时间覆盖UITableViewCell并实现我的自定义and。

我做得很匆忙。通过

代码语言:javascript
复制
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];
}

当然,在实现

代码语言:javascript
复制
- (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 );
}

祝你们大家好运

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5116026

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档