2

Hi everyone. I dragged a UIScrollView to my storyboard, then I added a UIView on top of that UIScrollView. This UIView loads another subview dynamically depending on what the server throws to this app.

The problem is the UIScrollView is not scrolling the content, even though I made the loaded UIView bigger than the UIScrollView. I'm not invoking [myScroller addSubView:myUiView]. Am I doing it right? Thanks in advance!

Steph Sharp
  • 11,462
  • 5
  • 44
  • 81

3 Answers3

0

You must set the content size of the scroll view.

Abdullah Shafique
  • 6,878
  • 8
  • 35
  • 70
0

Add this in your view controller.

- (void) viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];

    myScroller.contentSize = CGSizeMake(CGRectGetMaxX(myUiView.frame), CGRectGetMaxY(myUiView.frame));
}
Ahmed Mohammed
  • 1,134
  • 8
  • 10
  • I added it but nothing happens. I just connected the UIScrollView and the UIView to the view i added no code at all to handle the scroller could that be the problem? – Chris Villegas Jul 12 '13 at 23:09
  • yes. if myScroller and myUiView were not connected to the view controller this wouldn't work. They have to be connected for it to work. – Ahmed Mohammed Jul 12 '13 at 23:29
  • also make sure scrolling is enabled on interface builder or add the following to viewDidLoad. myScroller.scrollEnabled = YES; – Ahmed Mohammed Jul 12 '13 at 23:33
  • yes, everything is connected i added the scrollEnabled i even printed the myUiView height and its 1500, the myScroller height is 585 and still not scrolling. – Chris Villegas Jul 12 '13 at 23:39
0

For every time you change the content try calling

//removeFromSuperview the UIView was set as content view
self.myScroller.contentSize = self.myUiView.frame.size;
[myScroller addSubView:myUiView];

Don't forget to link both views on Interface Builder

PS: In this apporach the subView must not be inside the scrollView on IB

Lucas
  • 6,675
  • 3
  • 25
  • 43