UITableView dynamic cell heights only correct after some scrolling

I don’t know this is clearly documented or not, but adding [cell layoutIfNeeded] before returning cell solves your problem. – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { TableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@”TestCell”]; NSUInteger n1 = firstLabelWordCount[indexPath.row]; NSUInteger n2 = secondLabelWordCount[indexPath.row]; [cell setNumberOfWordsForFirstLabel:n1 secondLabel:n2]; [cell layoutIfNeeded]; // <- added return cell; }

Swift default AlertViewController breaking constraints

The following removes the warning without needing to disable animation. And assuming Apple eventually fixes the root cause of the warning, it shouldn’t break anything else. extension UIAlertController { func pruneNegativeWidthConstraints() { for subView in self.view.subviews { for constraint in subView.constraints where constraint.debugDescription.contains(“width == – 16”) { subView.removeConstraint(constraint) } } } } This can then … Read more

In iOS 12, when does the UICollectionView layout cells, use autolayout in nib

For all solutions, note that there is no need to explicitly call reloadData in viewDidLoad: it will happen automatically. Solution 1 Inspired by Samantha idea: invalidateLayout asynchronously in viewDidLoad. override func viewDidLoad() { super.viewDidLoad() //[…] for _ in 0 ..< 1000 { array.append(randomKeyByBitLength(Int(arc4random_uniform(8)))!) } DispatchQueue.main.async { self.collectionView.collectionViewLayout.invalidateLayout() } } Solution 2 (imperfect, see DHennessy13 improvement … Read more

What is ‘Vary for Traits’ in Xcode 8?

This is just an extension as to how to use “Vary Traits” quickly in your project for adding different layouts for iPad and iPhones. Please read this for understanding more on the Size classes. https://developer.apple.com/reference/uikit/uitraitcollection If you are skipping the example which follows below, do read the Summary in the end. OBJECTIVE : You need … Read more

How to adjust height of UICollectionView to be the height of the content size of the UICollectionView?

I would suggest the following: Add a height constraint to your collection view. Set its priority to 999. Set its constant to any value that makes it reasonably visible on the storyboard. Change the bottom equal constraint of the collection view to greater or equal. Connect the height constraint to an outlet. Every time you … Read more

What is NSLayoutConstraint “UIView-Encapsulated-Layout-Height” and how should I go about forcing it to recalculate cleanly?

Try to lower the priority of your _collapsedtextHeightConstraint to 999. That way the system supplied UIView-Encapsulated-Layout-Height constraint always takes precedence. It is based on what you return in -tableView:heightForRowAtIndexPath:. Make sure to return the right value and your own constraint and the generated one should be the same. The lower priority for your own constraint … Read more