Getting error when using directory to retrieve image
I am trying to recall the image that I have saved inside the directory to
show it in a UICollectionView. This is the code to do that.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
NSMutableArray *allImagesArray = [[NSMutableArray alloc] init];
NSArray *paths =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *location=@"Hats";
NSString *fPath = [documentsDirectory
stringByAppendingPathComponent:location];
NSArray *directoryContent = [[NSFileManager defaultManager]
directoryContentsAtPath: fPath];
for(NSString *str in directoryContent){
NSString *finalFilePath = [fPath stringByAppendingPathComponent:str];
NSData *data = [NSData dataWithContentsOfFile:finalFilePath];
if(data)
{
UIImage *image = [UIImage imageWithData:data];
[allImagesArray addObject:image];
}}}
However I am getting warnings that is showing in the last line telling me
that Local declaration of allImagesArray hides instance Variables. I do
not know why this is happening. If you want to see my other codes then
feel free to ask. Any help is greatly appreciated.
This is for my .h file
@interface HatsViewController : UICollectionViewController
<UICollectionViewDataSource, UICollectionViewDelegate>
{
NSMutableArray *allImagesArray;
}
No comments:
Post a Comment