动态的TableView单元格高度不正确直到滚动(iOS版8)之后 - 全附截图 [英] Dynamic TableView Cell Heights Incorrect Until After Scrolling (iOS 8) - full screenshots attached

查看:146
本文介绍了动态的TableView单元格高度不正确直到滚动(iOS版8)之后 - 全附截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

修改

内置从无到有,动态的tableview单元格高度完美的工作一个新的样本项目。然后,我尝试通过调整了我的项目,它的最低限度的复制,它仍然坏了(前几个细胞电瓶车)。附加完整的项目为工作和不工作的例子。项目/ code字面上看起来99%相同,对我的爱不能找出其中的1%的差别。这是我飞出的唯一的事情是,我使用了不同大小的类(温妮HANY VS wCompact hRegular但我无法想象会做任何事情给我的肖像只测试

工作项目:

不工作项目:

 工作(从​​头开始新的项目):
https://drive.google.com/file/d/0B_EIkjmOj3ImWXZjVFZMYXZmVGc/view?usp=sharing不工作(我的项目,清理到它的最低限度)
https://drive.google.com/file/d/0B_EIkjmOj3ImMGRNOXU2RlNkWEk/view?usp=sharing


们寻遍网络试图了解是怎么回事,但由于某些原因,我的单元格的高度是不正确的,直到我滚过原型细胞。

在初始负载:

和滚动过去的每个单元后:

背景色:

        cell.postTextLabel.backgroundColor =的UIColor orangeColor]
        subView.backgroundColor =的UIColor blueColor]
        contentView.backgroundColor =的UIColor brownColor]

没做什么太花哨这里:只是一个原型细胞,子视图,和三个标签(用户名,时间戳,文字)

下面的截图突出故事板我的约束:

我拉数据解析,和我重装我的数据而设定的tableView布局


            [self.tableView setNeedsLayout]
            [self.tableView layoutIfNeeded]
            [self.tableView reloadData];

和最后我的的cellForRowAtIndexPath 方法:

   - (UITableViewCell的*)的tableView:(UITableView的*)的tableView的cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    返回[自我postCellAtIndexPath:indexPath];
}
- (UITableViewCell中*)postCellAtIndexPath:(NSIndexPath *)indexPath {
    静态的NSString * PostCellIdentifier = @PostCell
    PostCell *电池=(PostCell *)[self.tableView dequeueReusableCellWithIdentifier:PostCellIdentifier forIndexPath:indexPath];    [个体经营configurePostCell:细胞atIndexPath:indexPath];    [细胞setNeedsLayout]
    [细胞layoutIfNeeded]    [单元setNeedsUpdateConstraints]
    [细胞updateConstraintsIfNeeded]    返回细胞;
}


解决方案

终于让我找到为什么它不工作的问题。我下载它被上传你所推动,并在其中做修改的项目。并发现您使用紧凑正大小类这会导致错误的问题。你的尺寸的类转换为之后的所有,任何它工作正常,并perfect.so解决方案的关键是改变的 wCompact hRegular 温妮HANY。有一个在code没有变化。

这是最初的回答。

详细的解答:

1)大小班先读<一个href=\"https://developer.apple.com/library/ios/recipes/x$c$c_help-IB_adaptive_sizes/chapters/SelectingASizeClass.html\"相对=nofollow>苹果的这个文件。

2)你破碎的演示大小类选择,如下所示:

在这里输入的形象描述

这表明你选择喜欢紧凑的宽度和高度定期特定视图意味着这个自动布局将只在特定的iPhone纵向工作。


  

紧凑型宽|常规高度结合指定布局的变化
  仅适用于大小类似于纵向iPhone设备
  方向。


  
  

控制wCompact hRegular指示紧凑的宽度和定期
  高度尺寸的类。


我用大小类的下方,还你的工作项目中,我可以看到大小类别如下:

在这里输入的形象描述

在此大小的类它的正常工作。

我不知道是不是苹果的错误或内容。 !

如果您想只支持肖像模式,只有iPhone手机,那么你可以选择iPhone在发展信息 - >设备。和方向可以选择纵向和设备的方向颠倒。

希望这可以帮助你找出问题。

EDIT

Built a new sample project from scratch and the dynamic tableview cell height is working flawlessly. I then tried to replicate by trimming down my project to it's bare minimum and it's STILL broken (first few cells buggy). Attaching full project for both working and not working examples. Project/code literally looks 99% identical and for the love of me can't figure out where the 1% difference is. The only thing that is popping out at me is that I used different size classes (wAny hAny vs wCompact hRegular but I can't imagine that would do anything given I'm testing in portrait only

Working project:

Not working project:

WORKING (new project from scratch):
https://drive.google.com/file/d/0B_EIkjmOj3ImWXZjVFZMYXZmVGc/view?usp=sharing

NOT WORKING (my project, cleaned up to it's bare minimum)
https://drive.google.com/file/d/0B_EIkjmOj3ImMGRNOXU2RlNkWEk/view?usp=sharing


Have scoured the web trying to understand what is going on, but for some reason my cell heights are incorrect until I scroll past the prototype cells.

Upon initial load:

And after scrolling past each cell:

Background colors: cell.postTextLabel.backgroundColor = [UIColor orangeColor]; subView.backgroundColor = [UIColor blueColor]; contentView.backgroundColor = [UIColor brownColor];

Not doing anything too fancy here: just a prototype cell, a subview, and three labels (username, timestamp, text).

Below screenshots highlight my constraints in Storyboard:

I pull data from Parse, and am reloading my data while setting tableView layout

[self.tableView setNeedsLayout]; [self.tableView layoutIfNeeded]; [self.tableView reloadData];

And lastly my cellForRowAtIndexPath method:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return [self postCellAtIndexPath:indexPath];
}


- (UITableViewCell *)postCellAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *PostCellIdentifier = @"PostCell";
    PostCell *cell = (PostCell *)[self.tableView dequeueReusableCellWithIdentifier:PostCellIdentifier forIndexPath:indexPath];

    [self configurePostCell:cell atIndexPath:indexPath];

    [cell setNeedsLayout];
    [cell layoutIfNeeded];

    [cell setNeedsUpdateConstraints];
    [cell updateConstraintsIfNeeded];



    return cell;
}

解决方案

Finally i found the problem why it is not working. I downloaded the Projects which were uploaded to drive by you, and do modifications in it. And found the issue that you use compact Regular size classes which causes error. After converting your size classes to Any, Any it works fine and perfect.so the key of the solution is change wCompact hRegular to wAny hAny. There is no change in code.

That was initial answer.

Detailed Answer :

1) for the size classes first read this document of apple.

2) In your broken demo the size classes are selected as given below :

This indicates that you selected specific view like compact width and regular height means this auto layout will only work in specific iPhone portrait orientation.

Compact Width | Regular Height combination specifies layout changes that apply only to sizes resembling iPhone devices in portrait orientation.

The control wCompact hRegular indicates the compact width and regular height size classes.

I used below size classes and also in your working project i can be able to see below size classes :

In this Size classes it's working fine.

I don't know is it apple's bug or what. !!!

If you want to support only portrait mode and only iPhones then you can choose iPhone in Development Info -> devices. and for orientation you can choose Portrait and upside down in Device orientation.

Hope this helps you to figure out the problem.

这篇关于动态的TableView单元格高度不正确直到滚动(iOS版8)之后 - 全附截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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