2

当我从键盘上按下一个键时,我有一个问题是让该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];
        }

    }
}

(对不起,这里是第一个问题)

4

0 回答 0