Skat-Game を作成しようとすると、次の問題が発生しました。
isBidding はブール値を示します。プログラムは特定の状態にあります。[desk selected] は現在選択されているプレイヤーを返すメソッド呼び出しです。chatStrings は辞書で構成され、プレイヤー、誰が入力したか、何を入力したかの文字列を保存します。
- (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;
}
これは、文字列の内容を決定する部分です。文字列は [event characters] メソッドによって提供されます。
-(void)displayChatString:(NSString *)string{
displayString = [displayString stringByAppendingString:string];
[self setNeedsDisplay:YES];
}
問題がある場合はこれです:
3 文字以上入力すると、ビューに NSRectSet{{{471, 574},{500, 192}}} が表示され、印刷しようとすると説明が返されません。
その後、EXC_BAD_ACCESS メッセージが表示されますが、解放していませんが (私が確認できる限り)、alloc と init で文字列も作成したため、自動解放プールに参加できません。デバッガーで変化するときのプロセスも監視しようとしましたが、責任あるコードは見つかりませんでした。
ご覧のとおり、私はまだ Cocoa (およびプログラミング全般) の初心者なので、誰かがこれを手伝ってくれたら本当にうれしいです。