J'essaie d'obtenir un bouton d'interface utilisateur pour interagir avec une étiquette d'interface utilisateur via Xcode et Interface Builder. Que dois-je changer dans ce code pour le faire? (J'ai tout lié dans Interface Builder déjà. L'application se bloque au moment où j'appuie sur le bouton.)iPhone Tap Counter
@synthesize window;
@synthesize label;
@synthesize anotherLabel;
@synthesize myButton;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[myButton setTitle:@"Press Here" forState:UIControlStateNormal];
window.backgroundColor = [UIColor grayColor];
label.text = [[NSDate date] description];
// Override point for customization after application launch.
[myButton addTarget:anotherLabel action:@selector(doButton:) forControlEvents:UIControlEventTouchUpInside];
[window makeKeyAndVisible];
return YES;
}
-(void) doButton:(UILabel *)anotherLabel{
static int count;
count++;
}
Merci pour la réponse! Je semble avoir une erreur quand je remplace le NSString. "Types contradictoires pour 'count'. Comptez-vous connaissez ce qui cause l'erreur – thisislev
'int statique; nombre ++; NSString * countStr = [NSString stringWithFormat: @ "% d", count];? [anotherLabel setText: countStr];' – Emil
serait probablement mieux (nom de la chaîne était le même que le nom int) – Emil