title: Load a saved image from documents directory
body: <p>I have used the code given <a href="http://www.wmdeveloper.com/2010/09/save-and-load-uiimage-in-documents.html" rel="nofollow">here</a> to save and load images </p>
  
  <p>It works fine when i use it together in one view controller, but when i use the saveImage method in one view controller and try to load the image in another view controller the image returned  blank...</p>
  
  <p>In view controller A i use the following to save a image</p>
  
  <pre><code>- (void)saveImage: (UIImage*)image
  {
      NSLog(@"saveimage called");
  
      if (image != nil)
      {
          NSLog(@"Image not null");
          NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                               NSUserDomainMask, YES);
          NSString *documentsDirectory = [paths objectAtIndex:0];
          NSString* path = [documentsDirectory stringByAppendingPathComponent:
                            @"test.png" ];
          NSData* data = UIImagePNGRepresentation(image);
          [data writeToFile:path atomically:YES];
          QrImageView.image = nil;
      }
  }
  </code></pre>
  
  <p>And in view controller say B I'm loading the image using..</p>
  
  <pre><code>- (UIImage*)loadImage
  {
      NSError *error;
  
      NSFileManager *fileMgr = [NSFileManager defaultManager];
  
      NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                           NSUserDomainMask, YES);
      NSString *documentsDirectory = [paths objectAtIndex:0];
      NSString* path = [documentsDirectory stringByAppendingPathComponent:
                        @"test.png" ];
      UIImage* image = [UIImage imageWithContentsOfFile:path];
  
      // Write out the contents of home directory to console
      NSLog(@"Documents directory: %@", [fileMgr contentsOfDirectoryAtPath:documentsDirectory error:&amp;error]);
  
      return image;
  }
  </code></pre>
  
  <p>I also get the content of the file in console but i dont understand why the image is blank</p>
  
  <pre><code>2013-07-06 14:13:19.750 YouBank[500:c07] Documents directory: (
      "test.png"
  )
  </code></pre>
  
  <p>Any idea what I'm doing wrong...</p>
  
  <pre><code>EDIT:
  </code></pre>
  
  <p>In the view controller B on the viewDidload method i do the following</p>
  
  <pre><code>- (void)viewDidLoad
  {
      [super viewDidLoad];
      // Do any additional setup after loading the view from its nib.
  
      ImageView.image=[self loadImage];
      ImageName.text = @"Cash Withdrawal";
  }
  </code></pre>