简体   繁体   English

UITableViewCell的textLabel与子视图标签重叠,如何解决? (iPhone开发人员)

[英]UITableViewCell's textLabel is overlapping a subview label, how can I fix it? (iPhone Dev)

As a follow up to: UILabel subview in UITableViewCell isn't showing up. 作为后续措施: UITableViewCell中的UILabel子视图未显示。 (iPhone Dev) (iPhone开发人员)

I have found out that the UILabel I added as a subview is showing up and positioned correctly, however when I set the cell's labelField, it seems to "overlap" the label I have added in the subview. 我发现我添加为子视图的UILabel可以正确显示并定位,但是当我设置单元格的labelField时,似乎“重叠”了我在子视图中添加的标签。

In other words "bar" only shows up when I comment out the first line of the following code snippet: 换句话说,“ bar”仅在我注释掉以下代码段的第一行时显示:


cell.textLabel.text = @"foo"
// sub view text label
UILabel *valueField = (UILabel *)[cell viewWithTag:111];
valueField.text = @"bar";

Is there a way to make the cell.textLabel not overlap the UILabel that's on the "same line"? 有没有一种方法可以使cell.textLabel不与“同一行”上的UILabel重叠? maybe by adjusting the underlying frame of cell.textLabel? 也许通过调整cell.textLabel的基础框架?

This problem also seems to only occur when I'm compiling with an SDK > 2.2.1, did something change that would affect this in 3.0? 当我使用SDK> 2.2.1进行编译时,似乎也只会出现此问题,是否做了一些更改会影响3.0中的版本?

Thanks 谢谢

UITableViewCell´s textLabel has a non clear background. UITableViewCell的textLabel背景不清晰。 I think that the position from your custom label to this one is so tiny that when the default textLabel shows text, it´s background covers your custom label (bar). 我认为从您的自定义标签到此标签的位置非常小,以至于当默认的textLabel显示文本时,其背景会覆盖您的自定义标签(栏)。

Change the background color for the default textLabel field in this message: 更改此消息中默认textLabel字段的背景颜色:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    [cell setBackgroundColor:[UIColor clearColor]];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM