1

I have placed a UIScrollView in a ViewController in IB and gave the view the tag:1. In viewDidLoad:, I have this code:

UIScrollView *scrollView = (id)[self.view viewWithTag:1];

scrollView.backgroundColor = [UIColor clearColor];
scrollView.opaque = NO;

[scrollView setScrollEnabled:YES];
[scrollView setContentSize:CGSizeMake(320, 800)];

I have a slider and a label in the ScrollView just to see if it scrolls, but it doesn't scroll at all. I get to change the backgroundColor to for example yellowColor, but it doesn't scroll. Is there a method or action i have to add? Please help! :)

calimarkus
  • 9,955
  • 2
  • 28
  • 48
Henrik LP
  • 159
  • 9
  • your code working fine dear some where else you went wrong once check.is there any view with same tag or like that. – Balu Apr 25 '13 at 09:28
  • Well, i suspect that it is the fact that i have an initial viewController where i press a tableviewCell which leads me to the view with the scrollview. Can this have something to do with thhis? – Henrik LP Apr 25 '13 at 09:32

5 Answers5

2

I had the same problem not long ago, but this did the trick.

Use -(void)viewDidAppear:(BOOL)animated { ... }

-(void)viewDidAppear:(BOOL)animated  {

    [super viewDidAppear:YES];

    scrollView.backgroundColor = [UIColor clearColor];

    scrollView.opaque = NO;

    [scrollView setScrollEnabled:YES];

    [scrollView setContentSize:CGSizeMake(320, 800)];

    [super viewDidLoad];
}

Also declare the UIScrollView in your header

@property (retain, nonatomic) IBOutlet UIScrollView *scrollView;
maelswarm
  • 1,163
  • 4
  • 18
  • 37
2

Try Like this

UIScrollView *scrollView = (id)[self.view viewWithTag:1];
scrollView.frame=CGRectMake(0, 0, 320, 460);
[self.view addSubview:scrollView];
scrollView.backgroundColor = [UIColor clearColor];
scrollView.opaque = NO;
[scrollView setScrollEnabled:YES];
[scrollView setContentSize:CGSizeMake(320, 800)]; 

because when the scroll view height cross the current view height then only its get scrollable.

Ganesh G
  • 1,991
  • 1
  • 24
  • 37
0
scrollView.backgroundColor = [UIColor clearColor];

change this to something bright like red or green for testing.

UIScrollView *scrollView = (id)[self.view viewWithTag:1];
scrollView.backgroundColor = [UIColor clearColor];

also make sure your scrollview isnt nil (after obtaining from [self.view viewWithtag:1]. otherwise the code seems OK

EDIT

select scroll view in interface builder > go to attributes editor > tick scrolling enabled

enable scrolling

nsuinteger
  • 1,503
  • 12
  • 21
0

here may be its problem with set TopBar of UIView with UINavigationBar from xib and also BottomBar of that... Here from XIB first select main UIView after click on Attribute Inspector after in Simulated metrics set NavigationBar as a TopBar and after set frame of UIScrollView in XIB.

try with bellow code it will worked ..

[scrollView setContentSize:CGSizeMake(320, 844)];
Paras Joshi
  • 20,427
  • 11
  • 57
  • 70
0

try to add this code in viewWillAppear

UIScrollView *scrollView = (UIScrollView *)[self.view viewWithTag:1];
scrollView.frame=CGRectMake(0, 0, 320, 400);
scrollView.backgroundColor = [UIColor clearColor];
[scrollView setScrollEnabled:YES];
[scrollView setContentSize:CGSizeMake(320, 800)]; 
[scrollView setUserInteractionEnabled:YES];

hope will help you

Nirav Gadhiya
  • 6,342
  • 2
  • 37
  • 76