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

发布于 2024-10-19 11:01:59 字数 499 浏览 7 评论 0原文

好吧,事情就是这样,已经花了两天时间尝试构建一个带有字幕样式的像样的表格视图单元。

所以我重写了 'tableview:heightforrowatindex:' 方法。美好的 我还将详细信息的行数设置为 0。

这在 ios4.0 中工作正常

,但对于 ios 3.0 则不行 看起来textlabel 和detailtextlabel 在顶部有一定的边距,这将所有单元格内容向下推以与下面的单元格重叠。 这是疯狂的行为。我找不到在其内容视图中设置 textlabel/detailtextlabel 位置的方法。

请帮忙。 在 iOS4 与 iOS3 中调整 UITableViewCells 大小 这家伙说他将实现自己的控件。但这工作量太大,对我来说很难。 一定有人已经知道有一种方法可以绕过这个问题。 谢谢

ok here's the thing, it's been two days now trying to build a decent tableview cell with subtitles style.

so i overrided the 'tableview:heightforrowatindex:' method. fine
i also put the numberoflines for the details to 0.

this works fine in ios4.0

but for ios 3.0 it doesn't
it appears that the textlabel and the detailtextlabel are having certain margins at the top which pushes all the cell content downwards to overlap the cell below.
This is crazy behaviour. and i couldn't find a way to set the textlabel/detailtextlabel location inside its content view.

Please help.
Resizing UITableViewCells in iOS4 versus iOS3 This guy said he's going to implement his own controls. but that's too much work, and it's hard for me.
There must be a way that someone already knew to bypass this problem.
thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

捂风挽笑 2024-10-26 11:01:59

实际上,苹果公司的人似乎并没有真正使 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 );
}

祝大家好运

actually it seems that the people at apple didn't really make the uitableviewcell as customizable as would a normal developer hope.

so you would have to customize it by yourself.
and sinsce i didn't have time to override UITableViewCell and implement my custom one.

I have done it hastingly. through

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];
}

of course while implementing

- (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 );
}

good luck to all of you

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文