UIScrollView subviews not showing at first
- by igul222
I created a custom UIScrollView subclass that works a like a UITableView, keeping a collection of subviews and re-using them whenever the user scrolls. It's implemented like this:
-(void)layoutSubviews {
for(UIView *subview in [self subviews])
[subview removeFromSuperview];
// then re-add subviews after changing the frame and some attributes
}
This works fine with simple UIViews, but when I try to do it with a UIView that has a UILabel subview, the "base" view appears fine, but the UILabel doesn't show up at all. I can get the UILabel to show up by scrolling the entire UIView off screen and then bringing it back on. What could be causing this?
So far, I've tried calling [myUIView setNeedsLayout], [myUIView setNeedsDisplay], and [myUIView layoutIfNeeded] from various places. None of them worked, and the last one crashed my app. I've also done the same thing to myUIScrollViewSubclass, with similar results.