Problem
In the user view my (a UIScrollViewsubclass), I call setNeedsLayoutin response to the "reload data" event (triggered by an external source). In most cases, this works correctly, and layoutSubviewsis called when the next view layout loop occurs. Sometimes, however, layoutSubviewsit is not called! Until now, I have lived with "certain knowledge," which setNeedsLayoutalways evokes layoutSubviews. Apparently, I was wrong. I even tried to call layoutIfNeededafter setNeedsLayout, but still did not have time.
Question
Obviously, I would like to solve my specific problem. On the other hand, I would like to improve my understanding of the presentation layout process in iOS, so I formulate my question in a general way: do you know about any conditions that may interfere with layoutSubviewsbeing called after it has setNeedsLayoutbeen called? Answers that focus on UIScrollVieware highly welcome, since that is where I have problems.
Problem context
I'm on iOS 7.1 using Xcode 5.1.1. Notes on implementing my custom scroll view:
- In the scroll view, there is one kind of container type
UIViewthat always matches the size of the scroll content - The scroll implementation
layoutSubviewsputs custom subtasks in the container view, manually calculating subviews frames
reloadData:
- (void) reloadData
{
[self removeAllSubviewsFromContainerview];
self.contentOffset = CGPointMake(0, 0);
CGFloat contentWidth = [self calculateNewContentWidth];
self.contentSize = CGSizeMake(contentWidth, self.frame.size.height);
[self setNeedsLayout];
}
, : , :
layoutSubviews , . layoutSubviews - not, , . , UIScrollView, .. layoutSubviews UIScrollView, . , , "" - layoutSubviews , , .layoutSubviews , UILabel subviewslayoutSubviews , , Auto Layout subviews
, Auto Layout - , , setNeedsLayout.