Essayer de créer un Skat-jeu, j'ai rencontré le problème suivant:Comportement étrange de NSString dans NSView
isBidding est une indicationg valeur booléenne, le programme est dans un certain état, [bureau sélectionné] est une méthode appelant revenir le joueur actuellement sélectionné, chatStrings se compose des dictionnaires, des chaînes d'économie avec le joueur, qui a tapé, et ce qu'il tapés
- (void)drawRect:(NSRect)rect{
NSMutableDictionary * attributes = [NSMutableDictionary dictionary];
[attributes setObject:[NSFont fontWithName:playerFont size:playerFontSize] forKey:NSFontAttributeName];
[attributes setObject:playerFontColor forKey:NSForegroundColorAttributeName];
[[NSString stringWithFormat:@"Player %i",[desk selected] + 1] drawInRect:playerStringRect withAttributes:attributes];
if (isBidding){
[attributes setObject:[NSFont fontWithName:chatFont size:chatFontSize] forKey:NSFontAttributeName];
[attributes setObject:chatFontColor forKey:NSForegroundColorAttributeName];
int i;
for (i = 0; i < [chatStrings count]; i++, yProgress -= 20){
if (isBidding)
[[NSString stringWithFormat:@"Player %i bids: %@",
[[[chatStrings objectAtIndex:i]valueForKey:@"Player"]intValue],
[[chatStrings objectAtIndex:i]valueForKey:@"String"]],
drawAtPoint:NSMakePoint([self bounds].origin.x, yProgress) withAttributes:attributes];
else
[[NSString stringWithFormat:@"Player %i: %@",[[[chatStrings objectAtIndex:i] valueForKey:@"Player"]intValue],
[[chatStrings objectAtIndex:i]valueForKey:@"String"]]
drawAtPoint:NSMakePoint([self bounds].origin.x, yProgress) withAttributes:attributes];
}
}
if (isBidding)
[[NSString stringWithFormat:@"Player %i bids: %@",[desk selected] + 1, displayString]
drawAtPoint:NSMakePoint([self bounds].origin.x, yProgress) withAttributes:attributes];
else
[[NSString stringWithFormat:@"Player %i: %@",[desk selected] + 1, displayString]
drawAtPoint:NSMakePoint([self bounds].origin.x, yProgress) withAttributes:attributes];
yProgress = chatFontBegin;
}
Ceci est la partie la détermination du contenu de la chaîne, la chaîne est apportée par un [événement caractères] méthode.
-(void)displayChatString:(NSString *)string{
displayString = [displayString stringByAppendingString:string];
[self setNeedsDisplay:YES];
}
Le problème se pose est la suivante:
lors de la frappe dans plus de deux lettres, l'affichage affiche NSRectSet {{{471, 574}, {500, 192}}} et retourne plus discription quand j'essaie de l'imprimer.
puis j'obtiens un message EXC_BAD_ACCESS, bien que je ne l'ai pas publié (pour autant que je puisse voir) J'ai également créé la chaîne avec alloc et init, donc je ne peux pas être dans le pool autorelease. J'ai également essayé de regarder le processus quand il change avec le débogueur, mais je n'ai trouvé aucun code responsable.
Comme vous pouvez le voir, je suis toujours un débutant dans Cocoa (et la programmation en général), donc je serais vraiment heureux si quelqu'un pouvait m'aider avec ça.