Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy won't UIScrollView scroll fully after adding objects? Using storyboard, ARC, and Xcode 4.5.2
    text
    copied!<p>So, I know there are similar questions to mine, but maybe not exact (so please don't mark me down -- just warn me or something). I have searched for days for the solution to this SIMPLE issue. Using storyboards, ARC, and Xcode 4.5.2, I simply need to put a bunch of labels inside a UIScrollView and have it scroll vertically. I've tried so many combinations of setting frame sizes and content sizes within viewDidLoad, viewDidAppear, and viewWillAppear, but to no avail. <strong>The scroll view scrolls perfectly when there's nothing inside of it, but when I add labels to it, the scrolling only scrolls a very short section.</strong></p> <p>Note: I need to use auto layout, otherwise my whole project will get messed up.</p> <p>Here's my current code...</p> <p><strong>.h file:</strong></p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface MortgageRatesViewController : UIViewController &lt;UIScrollViewDelegate, UIScrollViewAccessibilityDelegate&gt; - (IBAction)backButton:(id)sender; @property (strong, nonatomic) IBOutlet UIView *mortgageView; @property (weak, nonatomic) IBOutlet UIScrollView *scrollView; @end </code></pre> <p><strong>.m file:</strong></p> <pre><code>#import "MortgageRatesViewController.h" @interface MortgageRatesViewController () @end @implementation MortgageRatesViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } //------------------------------------------------------- - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"appBackgroundColor.png"]]; [self.scrollView setScrollEnabled:YES]; [self.scrollView setContentSize:CGSizeMake(0, 809)]; } //--------------------------------------------------------------- //--------------------------------------------------------------- //-(void)viewWillAppear:(BOOL)animated{ // // // [super viewWillAppear:animated]; // // // [self.scrollView setFrame:CGRectMake(0, 0, 320, 808)]; // // //} //--------------------------------------------------------------- -(void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [self.view addSubview:self.scrollView]; [self.scrollView setScrollEnabled:YES]; [self.scrollView setContentSize:CGSizeMake(0, 809)]; } //------------------------------------------------------------- - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (IBAction)backButton:(id)sender { [self dismissViewControllerAnimated:YES completion:NO]; } @end </code></pre> <p><strong>Note: having viewWillAppear commented out has made no difference.</strong></p> <p><strong>EDIT: I POSTED THE SOLUTION BELOW. HOPE IT HELPS OTHERS!</strong></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload