title: iPhone: setting an image programmatically from the Documents folder
body: <p>Hi I have a UIImageView Outlet in one of my views called promoBanner. I am trying to write code that will set this outlet programmatically. Basically, the app ships with an image in the NSBundle. But what I want to ensure that it fetches the image from the documents folder. I want to do this is because in the future there will be different "promotions" and the app should display the correct image in the "promoBanner" image view. Here is the code that I wrote but Im not sure why its not working. Could someone please give me an idea:</p>
  
  <pre><code>- (void)viewDidLoad
  {
      [super viewDidLoad];
      //==========================================================================
      NSError *error;
      NSString *errorDesc = nil;
      NSPropertyListFormat format;
      NSData *promoImg;
      NSString *rootPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
      NSString *promoImgDocPath = [rootPath stringByAppendingPathComponent:@"promoBanner.png"];
      NSFileManager *fileManager = [NSFileManager defaultManager];
  
      if (![fileManager fileExistsAtPath:promoImgDocPath]) 
         {
          NSString *plistBundlePath = [[NSBundle mainBundle] pathForResource:@"promoBanner" ofType:@"png"];
          [fileManager copyItemAtPath:plistBundlePath toPath:promoImgDocPath error:&amp;error]; 
          if(![fileManager fileExistsAtPath:promoImgDocPath])
             {
              NSLog(@"The copy function did not work, file was not copied from bundle to documents folder");
             }
         }
  
      self.promoBanner.image =[UIImage imageWithContentsOfFile:promoImgDocPath];
  
      if (!self.promoBanner.image) 
         {
          NSLog(@"Error setting image: %@, format: %d", errorDesc, format);
         }
  </code></pre>
  
  <p>Thanks a lot
  Error:</p>
  
  <pre><code>Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSFileManager copyItemAtPath:toPath:error:]: source path is nil'
  </code></pre>
  
  <p><em>*</em> Call stack at first throw:</p>
  
  <p>CoreFoundation 0x3759dc7b __exceptionPreprocess + 114</p>
  
  <p>libobjc.A.dylib 0x32d9bee8 objc_exception_throw + 40</p>
  
  <p>CoreFoundation 0x3759dac3 +[NSException raise:format:arguments:] + 70</p>
  
  <p>CoreFoundation 0x3759daf7 +[NSException raise:format:] + 30</p>
  
  <p>Foundation 0x351a8653 -[NSFileManager copyItemAtPath:toPath:error:] + 90</p>
  
  <p>Restaurant 0x000068c3 -[AboutViewController viewDidLoad] + 286</p>
  
  <p>UIKit 0x35926e60 -[UIViewController view] + 160</p>