0

这个想法是创建多个对象,当单击按钮时,第一个创建的对象将首先被删除,依此类推。例如,它会创建对象#1,然后是 2,然后是 3,当第一次单击按钮时,它将首先删除 1,然后是 2,然后是 3。

这是我在数组中创建项目的代码:

//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];

然后这里是运动代码

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];
}

这是删除某个 x 位置以外的项目的代码:

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

不幸的是,这不起作用。对我有什么想法或可能的解决方案吗?

4

2 回答 2

1
-(IBAction)btnDelete_Clicked:(id)sender
{
    NSInteger x=0;
    if(x <= arrImages.count)
    {
        [arrImages removeObjectAtIndex:x];
        x=x+1;
        NSLog(@"%@",arrImages);
    }
}
于 2015-01-26T10:25:47.333 回答
0

这很简单。
你有一个数组,例如aryImages.
使用整数:

int x=0;

 -(IBAction)removeObject
    {
    if(x < = [aryImages count])
    {
        [aryImages removeObjectAtIndex:x];
        x+=1;
    }

    }
于 2012-10-24T23:46:13.157 回答