2010-03-13 3 views
1

MacRuby 위임에 NSTextField있는에 textDidChange 이벤트를 바인딩하고 난 아주 간단한 MacRuby 위임 생성 :내가 창 내 NSTextField있는이

class ServerInputDelegate 
    attr_accessor :parent 

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

을 내가 컨트롤의 위임 설정을 시도했다 :

alt text http://grab.by/31Kr

나는이 델리게이트에 대해 생각할 수있는 모든 다른 객체와 윈도우를 설정해 보았습니다. 다른 대표 (예 : 응용 프로그램)와 applicationDidFinishLaunching 같은 이벤트를 제대로 설정하려고 시도했습니다.

이 NSTextField의 내용이 변경 될 때마다이 이벤트가 트리거되도록하기 위해 누락 된 트릭이 있습니까?

답변

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} 
} 
3

textDidChange:는 아마도 혼동, 단지 NSText (따라서 NSTextView) 오브젝트 작동 의미 NSTextDelegate method이다. NSTextField의 경우 NSControl delegate 메서드 controlTextDidChange:을 사용해야합니다. 하위 클래스를 만들 필요가 없습니다.

+0

이 질문에 답한 것이 아니라 다른 문제를 해결했기 때문에 투표하는 것이 좋습니다. 감사합니다. – Reuben