It's my first question, so sorry if I make any mistake.

I have an Objective-C application doing basically: Showing photos taken earlier, taking and saving new photos.

In my first view I have this code working to show earlier photos inside a collection view:

```
-(void)viewDidLoad {
    [super viewDidLoad];

    paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    documentsDirectory = [paths objectAtIndex:0];
    imagePaths = [[NSBundle bundleWithPath:documentsDirectory] pathsForResourcesOfType:@"png" inDirectory:nil];
    imageCount = imagePaths.count;
}

```

And,

```
-(void)viewWillAppear:(BOOL)animated{    
    paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    documentsDirectory = [paths objectAtIndex:0];
    imagePaths = [[NSBundle bundleWithPath:documentsDirectory] pathsForResourcesOfType:@"png" inDirectory:nil];
    imageCount = imagePaths.count;
    //NSLog([NSString stringWithFormat:@"%d",imageCount]);
    [_collectionView reloadData];
}

```

Creating Collection view with following methods:

```
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return imageCount;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    PictureCollectionViewCell *cell = (PictureCollectionViewCell *) [_collectionView dequeueReusableCellWithReuseIdentifier:@"PictureCell" forIndexPath:indexPath];
    UIImage *image = [UIImage imageWithContentsOfFile:[imagePaths objectAtIndex:indexPath.row ]];

    cell.imageView.image = image;
    return cell;
}

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(80, 80);
}

```

And in another view, where I save the taken photo, i have this:

```
-(void) savePhotoMethod{    
    NSData* imageData = UIImagePNGRepresentation(imageView.image);
    NSString *fileName = [NSString stringWithFormat:@"%d",photoIndex ];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];

    NSString *imagePath =[documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png",fileName]];

    NSFileManager *fileManager = [NSFileManager defaultManager];
    [fileManager createFileAtPath:imagePath contents:imageData attributes:nil];

    /*if ([fileManager fileExistsAtPath:imagePath])
{
    NSLog(@"succes!!");
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];

    NSArray *imagePaths = [[NSBundle bundleWithPath:documentsDirectory] pathsForResourcesOfType:@"png" inDirectory:nil];
    int imageCount = imagePaths.count;
    NSLog([NSString stringWithFormat:@"%d",imageCount]);

    } I also have his control, so I know the photo is actually saved successfully, but the imageCount is still showing me the number like last photo is not counted.*/

    [self.navigationController popToRootViewControllerAnimated:YES];
}

```

My problem is, The first view is showing the earlier photos successfully when app first starts. But after taking a new photo, saving it and returning to the first view; `viewDidLoad` and `viewWillAppear` methods cannot find the last saved photo. Though when I exit the app and re-launch it again, I can see the last photos too.

Any ideas regarding to this problem or ideas to make my app more efficient is welcomed!