2012-06-21 9 views
7

Widokowe widoki NSTableView wydają się mieć tylko standardowe zachowanie, gdzie, aby pole tekstowe wewnątrz tabeli było pierwszym responderem, użytkownik musi kliknąć dwukrotnie lub jedno kliknięcie i "zachować spokój".W opartym na widoku NSTableView, w jaki sposób ustawić kontrolkę jako pierwszą odpowiedź jednym kliknięciem?

Jednak, biorąc pod uwagę ofertę NSTableViews opartą na elastycznym widoku, takie zachowanie nie zawsze jest pożądane, ponieważ obecnie możliwe jest zastosowanie wielu różnych i złożonych aplikacji niż tworzenie tabeli "starej szkoły".

Jak mogę łatwo wykonać kontrolę (prawdopodobnie w komórce razem z innymi kontrolkami) wewnątrz widoku NSTableView pierwszego reagującego jednym kliknięciem?

Odpowiedz

21

Aby rozwiązać ten problem, przesłonić tę metodę na NSTableView:

@interface NSResponder (NSControlEditingSupport) 

/* This is a responder chain method to allow controls to determine when they should become first responder or not. Some controls, such as NSTextField, should only become first responder when the enclosing NSTableView/NSBrowser indicates that the view can begin editing. It is up to the particular control that wants to be validated to call this method in its -mouseDown: (or other time) to determine if it should attempt to become the first responder or not. The default implementation returns YES when there is no -nextResponder, otherwise, it is forwarded up the responder chain. NSTableView/NSBrowser implements this to only allow first responder status if the responder is a view in a selected row. It also delays the first responder assignment if a doubleAction needs to (possibly) be sent. 'event' may be nil if there is no applicable event. 
*/ 
- (BOOL)validateProposedFirstResponder:(NSResponder *)responder forEvent:(NSEvent *)event NS_AVAILABLE_MAC(10_7); 

@end 

TAK i wrócić od razu do umożliwienia firstResponder być wykonane szybko. Tabela "opóźnia" tworzenie pierwszego respondenta, jeśli trafiło pole tekstowe, i nie pozwala na jego wykonanie, chyba że wiersz został wybrany jako pierwszy.

Powiązane problemy