title: Loading an image programmatically in iOS
body: <p>In my App for the iPad I'm trying to load an image file programmatically. The file is NOT part of my project, hence it is not referenced in XCode. There is no entry for the file in XCode's Groups and Files column. </p>
  
  <p>The image has to be loaded at runtime instead, it name being read from a Property List.</p>
  
  <p>I'm trying to load the file like this:</p>
  
  <pre><code>NSString* pathToImageFile = [[NSBundle mainBundle] pathForResource:@"MyImage" ofType:@"png" inDirectory:@"MyDirectory"];
  UIImage* retVal = [UIImage imageWithContentsOfFile:pathToImageFile];
  </code></pre>
  
  <p>In this case, <code>mydirectory</code> lives in the main bundle like this:</p>
  
  <pre><code>MyAmazingApp.app/MyDirectory/MyImage.png
  </code></pre>
  
  <p>Unfortunately, the Image will not load. I can't add the image file to my project, as its name is to be determined at runtime and cannot be known in advance. The file name is read from a config file (a Property List) at runtime instead.</p>
  
  <p>What am I doing wrong? Your help will be very much appreciated.</p>