You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[self.contentView layoutSubviews] at line 103 should be [self.contentView layoutIfNeeded]. (you shouldn't call layoutSubviews directly according to the UIKit docs.)
it's required because the [super layoutSubviews] (on line 98) only sets the frame for self.contentView and causes it to need layout (self.contentView.layer.needsLayout becomes YES) but doesn't actually cause contentView's subviews to be laid out. this means that self.bodyLabel doesn't have its frame set at this point. while this usually happens later, we add the [self.contentView layoutIfNeeded] on line 103 to force this to occur immediately.
additionally, I noticed you didn't have a [super layoutSubviews] at the end of your layoutSubviews.
having done the above, you should be able to get rid of lines 172 and 173.
The text was updated successfully, but these errors were encountered:
You are correct that layoutSubviews shouldn't be called directly, that's why the comment was there above it. I just re-tested using setNeedsLayout and layoutIfNeeded instead and it is working fine. I thought I had originally tested this and determined that only calling layoutSubviews directly on the contentView was actually working reliably, but I must have been mistaken.
As far as calling [super layoutSubviews] at the end, I haven't found this to be necessary. The act of setting the preferredMaxLayoutWidth causes the bodyLabel to need another layout pass, which appears to happen automatically by the system. You can test and see that Lines 172 & 173 are still required whether or not it is there.
I'll update the code now for the first point, but please feel free to fork the project and test on your own for the second. If you figure anything out don't hesitate to open a pull request!
[self.contentView layoutSubviews]
at line 103 should be[self.contentView layoutIfNeeded]
. (you shouldn't call layoutSubviews directly according to the UIKit docs.)it's required because the
[super layoutSubviews]
(on line 98) only sets the frame forself.contentView
and causes it to need layout (self.contentView.layer.needsLayout
becomesYES
) but doesn't actually causecontentView
's subviews to be laid out. this means thatself.bodyLabel
doesn't have its frame set at this point. while this usually happens later, we add the[self.contentView layoutIfNeeded]
on line 103 to force this to occur immediately.additionally, I noticed you didn't have a
[super layoutSubviews]
at the end of yourlayoutSubviews
.having done the above, you should be able to get rid of lines 172 and 173.
The text was updated successfully, but these errors were encountered: