在第一次加载的iOS 8自动高度细胞不正确的高度 [英] iOS 8 Auto height cell not correct height at first load

查看:159
本文介绍了在第一次加载的iOS 8自动高度细胞不正确的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个iOS的应用程序8在那里我有每个单元是基于某种标签的高度自动调整大小的搜索结果页面。然而,该视图后第一次加载时显示不自动调整大小的单元格。当你向下滚动随后的细胞大小正常。我在我的故事板布线了自动布局约束。我有以下的code在viewDidLoad中。

I have an iOS 8 application where I have a search results page that each cell is autosized based on the height of a certain label. However, after the view first loads the cells that are displayed don't autosize. After you scroll down the cells that follow are sized correctly. I am wiring up the auto layout constraints in my storyboard. I have the following code in viewDidLoad.

- (void)viewDidLoad {
    [super viewDidLoad];

    //configure tableView so that we use autolayout enabled row heights
    self.tableView.estimatedRowHeight = 68;
    self.tableView.rowHeight = UITableViewAutomaticDimension;
}

有没有其他人经历过这样?

Has anyone else experienced this?

推荐答案

是的,在故事板制作的意见和约束时,我已经看到了这个相同的问题(但不能与code补充意见)。 Iv'e通过自定义单元格类添加此code这个固定,

Yes, I've seen this same problem when making the views and constraints in the storyboard (but not with code added views). Iv'e fixed this by adding this code in the custom cell class,

-(void)didMoveToSuperview { 
    [self layoutIfNeeded];
}

这或许可以去其他地方,但这种方法似乎只调用一次,所以我认为这是应该做它的好地方。

This could probably go other places, but this method seems to be called only once, so I thought it was a good place to do it.

这篇关于在第一次加载的iOS 8自动高度细胞不正确的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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