title: iOS - Creating UIScrollView programatically, direct assignment vs property
body: <p>From Apples <a href="http://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/UIScrollView_pg/CreatingBasicScrollViews/CreatingBasicScrollViews.html#//apple_ref/doc/uid/TP40008179-CH101-SW11" rel="nofollow">documentation</a> they create a UIScrollView in <code>- (void)loadView</code> like this:</p>
  
  <pre><code>- (void)loadView {
      CGRect fullScreenRect=[[UIScreen mainScreen] applicationFrame];
      scrollView=[[UIScrollView alloc] initWithFrame:fullScreenRect];
      scrollView.contentSize=CGSizeMake(320,758);
  
      // do any further configuration to the scroll view
      // add a view, or views, as a subview of the scroll view.
  
      // release scrollView as self.view retains it
      self.view=scrollView;
      [scrollView release];
  }
  </code></pre>
  
  <p>So I take for granted that the scrollView var is an instance variable declared in the .h file? Why is it that they set the the <code>scrollView</code> var with a direct assignment? Shouldn't you use proper memory management (as with a synthesized property)?</p>
  
  <p>The reason I'm wondering is beacuse I'm myself am creating a <code>UIScrollView</code> in <code>- (void)loadView</code>. I have declared a UIScrollView property to get a handle to the ScrollView through my class. Right now it looks like this (and is working) but I'm wondering if my code is correct, I don't like the direct assignment call:</p>
  
  <pre><code>- (void)loadView {
  
      // Setup Scroll View
      // scrollView is a property setup as (nonatomic, retain) UIScrollView *scrollView;
  
      // Wouldn't it be better if used self.ScrollView instead?
      scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
  
      [scrollView setContentSize:CGSizeMake(1, 1)];
      [scrollView setDelaysContentTouches:NO]; 
  
      self.view = scrollView;
  
  }
  </code></pre>