UITextView n'affiche rien
Bonjour,
Je suis débutant dans la programmation sous xCode et je lis actuellement le bouquin de Michel Martin "Créez des applications pour iPhone, iPad et iPod Touch".
J'en suis au niveau du TP master mind
Mon problème est que rien ne s'affiche dans mon Text View.
Voici le code du fichier ViewController.h
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
{
int nombreChoisi;
}
@property (weak, nonatomic) IBOutlet UITextField *saisie;
@property (weak, nonatomic) IBOutlet UITextView *resultats;
- (IBAction)autrenombre:(id)sender;
- (IBAction)saisieReturn :(id)sender;
@end |
Le code du fichier ViewController.m
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize saisie;
@synthesize resultats;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
nombreChoisi = arc4random() % 9000 + 1000;
resultats.text = [NSString stringWithFormat:@"%@%d", @"Bravo, le résultat était ", nombreChoisi];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)autrenombre:(id)sender {
nombreChoisi = arc4random() % 9000 + 1000;
resultats.text = [NSString stringWithFormat:@"%@", @"J'ai choisiun nouveau nombre\r"];
}
- (IBAction)saisieReturn :(id)sender {
[sender resignFirstResponder];
// combien de numéro sont bien placé
int bienPlace = 0;
int charIndex;
unichar testChar1, testChar2;
for (charIndex = 0; charIndex < 4; charIndex++)
{
testChar1 = [saisie.text characterAtIndex:charIndex];
testChar2 = [[NSString stringWithFormat:@"%d", nombreChoisi] characterAtIndex:charIndex];
if (testChar1 == testChar2)
bienPlace++;
}
resultats.text = [NSString stringWithFormat:@"%@%@%d%@%@", saisie.text, @" : Bien placés : ", bienPlace, @"\r", resultats.text];
if (bienPlace == 4)
resultats.text = [NSString stringWithFormat:@"%@%d", @"Bravo, le résultat était ", nombreChoisi];
}
@end |
Je suis sous OSX 10.8.2 avec xCode 4.5.2.
Je n'ai aucune erreur de programmation ou quoi que ce soit.
Rien ne s'écrit dans mon Text View (résultats).
edit :
Si je fais un NSLog(@"%@", résultats.text);
Il m'affiche (null)
Je dois avoir un problème d'init ou je ne sais quoi....
Quelqu'un peut il m'aider ?
Merci