I have an array here, example I have 4 images on each column, each responds to its default index:
When an image is deleted for example index 1. as shown in the image below:
The index becomes 0,1,2 :
which I want to be is 0,2,3 (Which is the original array index):
Could anyone help me on how to achieve this?
my code for my array:
self.myImages = [NSMutableArray array];
for(int i = 0; i <= 10; i++)
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
NSString *savedImagePath = [documentsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"myImages%d.png", i]];
if([[NSFileManager defaultManager] fileExistsAtPath:savedImagePath]){
[images addObject:[UIImage imageWithContentsOfFile:savedImagePath]];
}
}
use an NSMutableDictionary instead
You can put another key in your dictionary which will correspond to the index before any removal of objects. Display it instead of the index and you will get the desired result.
edit 2:
And when you're getting the corresponding object, you do: