title: Dynamically created UIImageViews on iPhone not showing
body: <p>I've achieved the point of headdesk, trying to dynamically create UIImageView in iOS 4.2.</p>
  
  <p>This is the code that is causing me trouble:</p>
  
  <p>1)  The setup</p>
  
  <pre><code>UIImageView *iview = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 95, 149)];
  iview.tag = 200; // see note 1
  iview.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
  [self.view addSubview:iview];
  [iview release];
  </code></pre>
  
  <p>I've tried with both releasing and not releasing iview.</p>
  
  <p>2) The payoff</p>
  
  <pre><code>NSString *img = ...[see note 2];
  NSLog(@"Filename: %@", img);
  
  UIImageView *pIV = (UIImageView *)[self.view viewWithTag:200];
  if (pIV == nil) {
      abort();
  }
  
  UIImage *pI = [UIImage imageWithContentsOfFile:img];
  if (pI == nil) {
      abort();
  }
  [pIV setImage:pI];
  </code></pre>
  
  <p>This is expanded to show what I'm looking at, since the terse version wasn't working for me.</p>
  
  <p>Note 1:  Most of the above hardcoded values (200, the frame bounds, etc) are either #defines or computed in the forloop that the iview alloc code is within.  Left out for brevity, but let me know if you think it's relevent.  </p>
  
  <p>Note 2:  This is just a message that returns the filepath after looking in NSBundle etc.  The NSLog output is</p>
  
  <blockquote>
    <p>2011-01-30 22:09:54.767 ribbit[13529:207] Filename: /Users/rip/Library/Application Support/iPhone Simulator/4.2/Applications/C421AA9F-45BB-41AB-8CB0-1540FABB56D3/ribbit.app/cardfront_a7.png    </p>
  </blockquote>
  
  <p>The .png does exist, and both the sentinels aren't nil (so neither abort() happens).</p>
  
  <p>I'm convinced that it's just something basic.</p>
  
  <p>Things I've tried:</p>
  
  <p>1) Used IB to generate the UIImageView.  When it was wired up correctly, I could see the frame, and the image that was given as the default in IB showed.  I still could not, however, alter the image, which is why I moved to dynamically creating them...thought it would be simpler. Eh.</p>
  
  <p>2) Tried using instance variables for the various iviews, but that was unwieldy (there are ten of these UIImageView being generated) and they didn't work either.</p>
  
  <p>Because all three attempts failed with the same behavior (runs fine, just can't see the images), I'm assuming that it is just some silly little thing.</p>
  
  <p>I welcome any suggestions you might have. </p>