私は過去数日間研究しており、これを理解することはできません。私は同じことをするたくさんのボタンを持っています(クリックすると消えます)。私は独自のタグでそれぞれを定義しますが、どれが押されたのかはどのようにして決めるのですか?目的C:タグを使う
-(IBAction) tapBrick{
int x = brick.tag;
NSLog(@"%d", x);
//remove last brick
[brick removeFromSuperview];
//add to score
count++;
NSString *scoreString = [NSString stringWithFormat:@"%d", count];
score.text = scoreString;
//determine x y coordinates
int xPos, yPos;
xPos = arc4random() % 250;
yPos = arc4random() % 370;
}
-(void) produceBricks {
//determine x y coordinates
int xPos, yPos;
xPos = arc4random() % 250;
yPos = arc4random() % 370;
//create brick
brick = [[UIButton alloc] initWithFrame:CGRectMake(xPos,yPos + 60,70,30)];
[brick setBackgroundColor:[UIColor blackColor]];
[brick setTag:i];
[brick addTarget:self action:@selector(tapBrick) forControlEvents:UIControlEventTouchUpInside];
i++;
[self.view addSubview:brick];
}
プロデューサブリックは、タイマーによって2秒ごとに呼び出されます。
最後のスレッドでタグなしでこれを行う方法に関する回答があります:http://stackoverflow.com/questions/4515592/objective-c-removing-previous -ui-elements –
レコードの場合、タグはObjective Cのものではなく、UIViewクラス(およびその派生物)の機能です。 –