的iOS 7.1的UITableViewCell内容下面的人重叠 [英] iOS 7.1 UitableviewCell content overlaps with ones below

查看:184
本文介绍了的iOS 7.1的UITableViewCell内容下面的人重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有code,这是成功地工作在iOS 7.0而不是7.1。我有一个简单的tableview,用code:

   - (NSInteger的)numberOfSectionsInTableView:(UITableView的*)的tableView
{
    返回1;
} - (NSInteger的)的tableView:(UITableView的*)的tableView numberOfRowsInSection:(NSInteger的)部分
{
    返回10;
} - (CGFloat的)的tableView:(UITableView的*)的tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    返回70.0;
} - (UITableViewCell的*)的tableView:(UITableView的*)的tableView的cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    * UITableViewCell的细胞= [的tableView dequeueReusableCellWithIdentifier:@细胞forIndexPath:indexPath];    对于(的UIView *在cell.contentView.subviews视图){
        [查看removeFromSuperview]
    }    *的UILabel标签= [[的UILabel的alloc]初始化];
    label.text = [NSString的字符串]    对于(NSInteger的I = 0; I< 20;我++){
        label.text = [label.text stringByAppendingString:@标签字符串];
    }    label.translatesAutoresizingMaskIntoConstraints = NO;
    label.numberOfLines = 0;
    label.lineBreakMode = NSLineBreakByWorldWrapping;
    //label.lineBreakMode = NSLineBreakByTruncatingTail; //我已经试过这也
    [cell.contentView addSubview:标号];    *的NSDictionary字典= NSDictionaryOfVariableBindings(标签);
    [cell.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@H:| -8- [标签] -8- |选项​​:0的指标:无意见:快译通]];
    [cell.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@V:| -8- [标签]选项:0的指标:无意见:快译通]];    如果(indexPath.row == 0){
        label.textColor = [的UIColor colorWithRed:1.0绿色:0蓝:0阿尔法:1.0];
    }
    否则如果(indexPath.row == 1){
        label.textColor = [的UIColor colorWithRed:0绿色:1.0蓝:0阿尔法:1.0];
    }
    否则如果(indexPath.row == 2){
        label.textColor = [的UIColor colorWithRed:0绿色:0蓝:1.0阿尔法:1.0];
    }
    其他{
        label.textColor = [的UIColor colorWithWhite:0.3阿尔法:1.0];
    }    cell.backgroundColor = [的UIColor colorWithWhite:1.0阿尔法:1.0];
    返回细胞;
}

我有10rows 1section。每行重用我删除内容查看所有的子视图(我试过ALLOC-INIT的UITableViewCell,但具有相同的结果出来)。

在iOS 7.0中的UILabel仅显示在单元格它属于。但是在7.1的UILabel继续显示了另一种细胞。什么是interresting,当我点击单元格,它不再是由anothers overlaping,但只有直到我点击单元格的上方。
我的问题是,如何使它在7.1devices工作就像上7.0ones。

我想这两个模拟器和设备,我看了看的iOS 7.1 API的diff,但一无所获与此有关。

也许这是自动布局的问题,那我还有的UILabel的可变高度,但我必须这样做。我想在所有的UILabel文字,但仅显示的UILabel的一部分,可以在单元格,这是在7.0默认方式来显示,但7.1的变化这一点,我不为什么,为什么,以及如何处理它。

这是对于细节的说明图片的Dropbox文件夹:文件夹图片

更新:我试过之类的东西TESE,但没有为我工作

  cell.frame = CGRectMake(0,0,self.tableView.frame.size.width,70);
cell.contentView.frame = CGRectMake(0,0,self.tableView.frame.size.width,70);cell.opaque = NO;
cell.contentView.opaque = NO;cell.clearsContextBeforeDrawing = NO;
cell.contentView.clearsContextBeforeDrawing = NO;cell.clipsToBounds = NO;
cell.contentView.clipsToBounds = NO;


解决方案

这个问题与您的单元格的高度来完成。它是不会动态调整,对于你。

您可能会注意到,当滚动以上的看法超出视图重叠的文本将随之消失。

如果你想要你的文字在一定高度夹,那么你需要设置的行数,而不是将其设置为0,因为这会让它继续下去。

lineBreakMode ,因为它不会停止将不会生效。

(可选),你可以尝试设置裁剪的内容查看,以确保所有子视图留在里面。

根据你想要的最终结果,你可以做动态的高度和变化的基础上的内容。有一堆有关这样做题。

更新 - 裁剪的内容查看

我不得不尝试一下自己,但在代称,这里涉及到裁剪内容查看几个链接:

看起来是这样工作的:

  cell.clipsToBounds = YES;

So I have code, which is sucessfully working on iOS 7.0 but not in 7.1. I have a simple tableview, with code:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 10;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 70.0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];

    for (UIView *view in cell.contentView.subviews) {
        [view removeFromSuperview];
    }

    UILabel *label = [[UILabel alloc] init];
    label.text = [NSString string];

    for (NSInteger i = 0; i < 20; i++) {
        label.text = [label.text stringByAppendingString:@"label String "];
    }

    label.translatesAutoresizingMaskIntoConstraints = NO;
    label.numberOfLines = 0;
    label.lineBreakMode = NSLineBreakByWorldWrapping;
    //label.lineBreakMode = NSLineBreakByTruncatingTail; //I have tried this too
    [cell.contentView addSubview:label];

    NSDictionary *dict = NSDictionaryOfVariableBindings(label);
    [cell.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-8-[label]-8-|" options:0 metrics:nil views:dict]];
    [cell.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-8-[label]" options:0 metrics:nil views:dict]];

    if (indexPath.row == 0) {
        label.textColor = [UIColor colorWithRed:1.0 green:0 blue:0 alpha:1.0];
    }
    else if (indexPath.row == 1) {
        label.textColor = [UIColor colorWithRed:0 green:1.0 blue:0 alpha:1.0];
    }
    else if (indexPath.row == 2) {
        label.textColor = [UIColor colorWithRed:0 green:0 blue:1.0 alpha:1.0];
    }
    else {
        label.textColor = [UIColor colorWithWhite:0.3 alpha:1.0];
    }

    cell.backgroundColor = [UIColor colorWithWhite:1.0 alpha:1.0];
    return cell;
}

I have 1section with 10rows. With each row reused I delete all subviews from contentView(I tried alloc-init UITableViewCell, but came with the same results).

On iOS 7.0, UILabel is displayed only in cell it belongs to. But in 7.1 UILabel continues displaying over another cells. What is interresting, that when I click on cell, it stop being overlaping by anothers, but only till I click on cell above. My question is, how to make it work on 7.1devices like on 7.0ones.

I tried both simulator and device and I took a look at iOS 7.1 API Diffs, but found nothing related to this.

Maybe it is issue of Auto Layout, that i have variable height of UILabel, but I need to do so. I want to have all text in UILabel, but display only part of UILabel, that can be displayed in a cell, which is default behavior in 7.0, but 7.1 changes this and I don't why why and how to deal with it.

This is dropbox folder for images with detail explanation: Folder with images

Update: I tried things like tese, but nothing worked for me.

cell.frame = CGRectMake(0, 0, self.tableView.frame.size.width, 70);
cell.contentView.frame = CGRectMake(0, 0, self.tableView.frame.size.width, 70);

cell.opaque = NO;
cell.contentView.opaque = NO;

cell.clearsContextBeforeDrawing = NO;
cell.contentView.clearsContextBeforeDrawing = NO;

cell.clipsToBounds = NO;
cell.contentView.clipsToBounds = NO;

解决方案

The issue has to do with the height of your cell. It isn't going to dynamically adjust that for you.

You'll probably notice that as you scroll and the view above goes out of view the overlapping text will disappear with it.

If you are wanting your text to clip at a certain height, then you need to set the number of lines, rather than setting it to 0 since that will let it continue forever.

The lineBreakMode won't take effect since it isn't stopped.

Optionally you could try to set clipping on the contentView to make sure all subviews stay inside.

Depending on the end result you want, you could do dynamic heights and change based on the content. There are a bunch of SO questions related to doing this.

Update - clipping the contentView

I'd have to try it out myself, but in lieu of that, here are a couple links related to clipping the contentView:

Looks like this works:

cell.clipsToBounds = YES;

这篇关于的iOS 7.1的UITableViewCell内容下面的人重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆