Ask A Question

removing an object from an NSMutableArray xcode

Asked by Lucas Bullen on 10/20/2012 at 5:26 PM

The idea is that there are multiple objects being created and the one that was first created will get deleted first when a button is clicked and so on. For example it would create objects # 1 then 2 then 3 and when the button is clicked the first time it will first delete 1, then 2, then 3.

Here is my code for the creation of the items in the array:

//array of imageviews
aryImages= [[NSMutableArray alloc] init];
//creation code for the images
CGRect frame = CGRectMake(480, 180, 60, 55);
imgViewPicture = [[UIImageView alloc] initWithFrame:frame];
imgViewPicture.image=[UIImage imageNamed:@"flower.png"];
[self.view addSubview:imgViewPicture];

[aryImages addObject:imgViewPicture];

Then here is the movement code

for (int x = 0; x < [aryImages count]; x++) {
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1.5];
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];
    [UIView setAnimationDelegate:self];
    [imgViewPicture setFrame:CGRectMake(120, 180, 60, 55)];
    [UIView commitAnimations];

Here is the code for deleting the items beyond the certain x location:

 for (int x = 0; x < [aryImages count]; x++) {
        UIImageView *imgViewInQuestion = (UIImageView *)[aryImages objectAtIndex:x];
        if (imgViewInQuestion.frame.origin.x>=120) {
            [aryImages removeObjectAtIndex:x];

Unfortunately this does not work. Any ideas why or possible solutions for me? thanks!

View Full Answer On Stackoverflow


No responses yet. Be the first one!

    [Some content on this page is from Stackoverflow]