(BOOL)control:(NSControl *)control textView:(NSTextView *)inputfield doCommandBySelector:(SEL)commandSelectorを使用して、ユーザーが押したNSTextViewおよびNSTextFieldのキーを次のように検出しているとのことですが、
- (BOOL)control:(NSControl *)control textView:(NSTextView *)inputfield doCommandBySelector:(SEL)commandSelector
{
if(commandSelector == @selector(insertNewline:) )
{
//... a key is down
return YES; // We handled this command; don't pass it on
}
else
{
return NO;
}
}
私の質問は、そのようなコントロールが複数ある場合に、どのテキスト フィールドの下でキーが押されているかをどのように判断するかです。特定のテキストフィールドにキーが押されているかどうかを確認するために、次のようなタグを設定しましたが、機能しません。
- (BOOL)control:(NSControl *)control textView:(NSTextView *)inputfield doCommandBySelector:(SEL)commandSelector
{
if ([inputfield tag] == 100)
{
if(commandSelector == @selector(insertNewline:) )
{
//... a key is down
return YES; // We handled this command; don't pass it on
}
else
{
return NO;
}
}
else
{
return NO;
}
}
アドバイスありがとうございます。