当我从键盘按下某个键时,我在keyDown:
中为每个项目运行NSCollectionView
方法时遇到问题。
编辑:我的NSCollectionViewItem中有下一个代码,但不起作用,我该怎么做才能使acceptsFirstResponder
工作:
- (BOOL)acceptsFirstResponder
{
[[[self view] window] makeFirstResponder:self];
return YES;
}
- (void)keyDown:(NSEvent*)event
{
NSString *chars = [event characters];
unichar character = [chars characterAtIndex: 0];
if(!sound){
sound = [[NSSound alloc] initWithContentsOfFile:textFile.stringValue byReference:YES];
}
if ([checkButton state]==1) {
[sound setLoops:YES];
}else{
[sound setLoops:NO];
}
if(character == (int)'w'){
if ([sound isPlaying]){
[sound stop];
[sound release];
sound = nil;
} else {
[sound play];
}
}
}
(很抱歉做了很多改动,这是第一个问题)