私は毎秒 "ブリック"を作成しています。それをタップすると消えます。私の問題は、2番目以上のものが画面に表示された場合、直前のものをタップすると最も新しいものが削除され、画面からはまったく削除することはできません。私が持っているコードは次のとおりです。目的C:以前のui要素を削除する
- (NSTimer *)getTimer{
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector: @selector(produceBricks) userInfo:nil repeats:YES];
return timer;
}
-(IBAction) tapBrick {
//remove last brick
[bricks[count] removeFromSuperview];
//add to score
count++;
NSString *scoreString = [NSString stringWithFormat:@"%d", count];
score.text = scoreString;
}
-(void) produceBricks {
//determine x y coordinates
int xPos, yPos;
xPos = arc4random() % 250;
yPos = arc4random() % 370;
//create brick
bricks[count] = [[UIButton alloc] initWithFrame:CGRectMake(xPos,yPos + 60,70,30)];
[bricks[count] setBackgroundColor:[UIColor blackColor]];
[bricks[count] addTarget:self action:@selector(tapBrick) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:bricks[count]];
}
私はそれがbricks[count] removeFromSuperview
ラインというカウントは常に増加しているとしなければならない知っています。現在の配列の代わりにクリックされている配列のレンガをどのように参照しますか?