Every time that touchesBegan:withEvent:
is invoked, the following line in your code creates a new array, overwriting the previously created array:
mainImages = [[NSMutableArray alloc] init];
The array can therefore never have more than one entry. You must change your code so that the array is allocated only once. I suggest you move the line above to the initializer of your custom view class (typically initWithFrame:
).
If you absolutely must allocate the array within touchesBegan:withEvent:
, try the following rather crude solution:
static bool mainImagesAlreadyAllocated = false;
if (! mainImagesAlreadyAllocated)
{
mainImages = [[NSMutableArray alloc] init];
mainImagesAlreadyAllocated = true;
}