Ziel C: Verwendung von tags

Habe ich seit der recherche für den letzten paar Tagen und kann es nicht herausfinden. Ich habe eine Menge von Schaltflächen, die das gleiche tun (verschwinden, wenn Sie geklickt werden). Ich definiere jedes mit seinem eigenen tag, aber wie kann ich bestimmen, welche gedrückt wird?

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


}

Produzieren Ziegel genannt wird alle 2 Sekunden durch einen timer.

  • Sie erhalten Antworten darauf, wie dies zu tun, ohne tags in deinem letzten thread: stackoverflow.com/questions/4515592/...
  • Für den Rekord-tags sind ein Merkmal der UIView-Klasse - (und seine Derivate), nicht eine Objective-C ein.
InformationsquelleAutor Chris | 2010-12-26
Schreibe einen Kommentar