1

ウィンドウ内にNSTextFieldがあり、非常に単純なMacRubyデリゲートを作成しました。

class ServerInputDelegate
    attr_accessor :parent

    def textDidChange(notification)
        NSLog notification.inspect
        parent.filter
    end
end

そして、私はコントロールのデリゲートを設定しようとしました:

代替テキストhttp://grab.by/31Kr

このデリゲートに対して、ウィンドウと考えられる他のすべてのオブジェクトを設定してみました。また、他のデリゲート(たとえば、アプリケーション)に設定しようとしましたが、applicationDidFinishLaunchingなどのイベントが適切にトリガーされています。

このNSTextFieldの内容が変更されるたびにこのイベントがトリガーされるようにするために、私が見逃しているトリックはありますか?

4

2 に答える 2

3

textDidChange:, perhaps confusingly, is an NSTextDelegate method, which means it only works for NSText (and therefore NSTextView) objects. For an NSTextField, you should just use the NSControl delegate method controlTextDidChange: No need to subclass.

于 2011-04-29T00:40:18.683 に答える
3

NSTextField をサブクラス化し、IB で、サブクラス化するテキスト フィールドのクラスを「ServerInputDelegate」に設定します。入力を開始すると、オートコンプリートされます。

class ServerInputDelegate < NSTextField

    def textDidChange(notification)
        NSLog notification.description
        puts self.stringValue
    end

end

結果

2010-04-30 14:37:24.810 TextFieldTextChanged[69109:a0f] NSConcreteNotification 0x200350b00 {name = NSTextDidChangeNotification; object = <NSTextView: 0x2003b95e0>
    Frame = {{2.00, 3.00}, {436.00, 17.00}}, Bounds = {{0.00, 0.00}, {436.00, 17.00}}
    Horizontally resizable: YES, Vertically resizable: YES
    MinSize = {436.00, 17.00}, MaxSize = {40000.00, 40000.00}
}
于 2010-04-30T20:42:14.910 に答える