Reputation: 543
I'm having trouble resizing the content of a UITableViewCell
when the device rotates to landscape (and therefore view width increases).
For context, this is part of a universal split view app and is only occurring on iPhone 8 in the simulator (which doesn't support split view). Later devices which do support the split view have no issue.
In my UITableViewController
, translatesAutoresizingMaskIntoConstraints = false
, and 'Follow Readable Width' is unchecked in IB. I have also added:
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
self.tableView.reloadData()
}
The tableView
also has a custom UITableViewCell
to which I've added:
override func layoutSubviews() {
uniqueIDLeading.constant = (self.contentView.frame.width * 0.4)
layoutIfNeeded()
}
No errors or warnings in the console. Any other ideas?
Upvotes: 0
Views: 793
Reputation: 1
In my case, and I'm sure in yours, I forgot to call a super class method.
open override func layoutSubviews() {
super.layoutSubviews()
.......
}
Upvotes: 0
Reputation: 11
I have the similar issue today, but I am not using a custom cell. I solved it with the following code.
Swift:
self.tableView.autoresizingMask = .flexibleWidth
Objective-C:
self.tableView.autoresizingMask=UIViewAutoresizingFlexibleWidth;
Upvotes: 1
Reputation: 543
Eventually fixed with the following in custom UITableViewCell
class.
override func layoutSubviews() {
super.layoutSubviews()
autoresizingMask = .flexibleWidth
layoutIfNeeded()
}
Upvotes: 3