问题描述
我有一个 iOS 8 应用程序,其中有一个搜索结果页面,每个单元格都会根据某个标签的高度自动调整大小.但是,在视图首次加载后,显示的单元格不会自动调整大小.向下滚动后,随后的单元格大小正确.我正在我的故事板中连接自动布局约束.我在 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;
}
有其他人经历过吗?
推荐答案
是的,我在故事板中制作视图和约束时也遇到过同样的问题(但没有添加代码的视图).我已经通过在自定义单元类中添加此代码来解决此问题,
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 自动高度单元格在第一次加载时高度不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)