【发布时间】:2011-02-13 08:20:24
【问题描述】:
我根据 Aaron Hillegass 的 COCOA PROGRAMMING 书(第 6 章)编写了一个应用程序。
该应用程序显示语音合成器的可用声音。
表格视图的init和delegate方法如下:
- (id)init
{
[super init];
NSLog(@"init");
speechSynth = [[NSSpeechSynthesizer alloc] init];
[speechSynth setDelegate:self];
availableVoices = [[NSSpeechSynthesizer availableVoices] retain];
return self;
}
- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn*)aTableColumn row:(NSInteger)rowIndex
{
NSString * aVoice = [availableVoices objectAtIndex:rowIndex];
NSDictionary *voiceDict = [NSSpeechSynthesizer attributesForVoice:aVoice];
return [voiceDict objectForKey:NSVoiceName];
}
我有关于这一行的问题 1:
availableVoices = [[NSSpeechSynthesizer availableVoices] **retain**];
为什么要保留?我尝试不保留,弹出窗口,但是我在窗口上移动鼠标,程序被丢弃:
(gdb) 继续 2011-02-13 15:57:37.671 SpeakLine[4384:80f] ** -[CFArray objectAtIndex:]: 消息发送到释放的实例 0x187e20*
问题 2:
我调试这个程序,即使我没有写retain,availableVoices也可以,但是Xcode调试器只显示9个内容,为什么?怎样才能看到数组的所有内容?
问题 3:
为什么程序在期中而不是一开始就崩溃了? NSSpeechSynthesizer 的内容是什么时候发布的?
【问题讨论】:
标签: objective-c cocoa xcode