Je suis un développeur iPhone débutant. Mon code est le suivant:Modifier le texte d'un UILabel (UIBarButtonItem) sur une barre d'outils par programme
UIBarButtonItem *fixedSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
UILabel *lblTotCaratteri = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 25, 15)];
lblTotCaratteri.textAlignment = UITextAlignmentCenter;
lblTotCaratteri.font = [UIFont italicSystemFontOfSize:13.0];
lblTotCaratteri.textColor = [UIColor greenColor];
lblTotCaratteri.backgroundColor = [UIColor clearColor];
lblTotCaratteri.adjustsFontSizeToFitWidth = YES;
lblTotCaratteri.text = @"0";
UIBarButtonItem *lblCaratteri = [[UIBarButtonItem alloc] initWithCustomView: lblTotCaratteri];
inserimentoToolbar.items = [NSArray arrayWithObjects:fixedSpace, lblCaratteri, fixedSpace, nil];
Donc à mon avis, j'ai une UITextView et cette barre d'outils créés par programme. Je veux changer le texte de l'étiquette chaque fois que j'ajoute un caractère à UITextView. Chaque fois que le texte UITextView change, je peux afficher une alerte à chaque touche enfoncée. Je n'arrive pas à comprendre comment changer le texte de l'étiquette. J'espère avoir expliqué mon scénario. Désolé pour mon anglais. Salutations, Luca.
Avez-vous une référence à lblTotCaratteri? Sinon, déclarez-le dans votre @interface. Dans ce cas, ne pas le redéclarer avec UILabel * (ligne 2 ci-dessus). Ensuite, vous pouvez appeler lblTotCaratteri.text = @ "newtexthere". – mjhoy
Ça a marché! Je l'ai ajouté à l'interface et bien sûr je ne l'ai pas redéclaré. Comment puis-je marquer votre commentaire comme réponse? Merci encore! – crash
J'ai remarqué que votre variable s'appelle fixedSpace, mais sa valeur est en fait FlexibleSpace. Est-ce une erreur? – mk12