iOS 8 自动高度单元格在第一次加载时高度不正确

iOS 8 Auto height cell not correct height at first load(iOS 8 自动高度单元格在第一次加载时高度不正确)
本文介绍了iOS 8 自动高度单元格在第一次加载时高度不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 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 自动高度单元格在第一次加载时高度不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Get an event when UIBarButtonItem menu is displayed(显示UIBarButtonItem菜单时获取事件)