在基于视图的NSTableView中,如何使控件第一个响应者单击? [英] In a view-based NSTableView, how make a control the first responder with a single click?

查看:181
本文介绍了在基于视图的NSTableView中,如何使控件第一个响应者单击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于视图的NSTableView似乎只有标准的行为,为了使表中的文本字段成为第一个响应者,用户必须双击或单击并保持冷静。然而,考虑到基于视图的NSTableViews提供的灵活性,这种行为并不总是希望的,因为现在有许多不同的和复杂的应用程序可能比只是做一个老学校表。



我如何在一个基于视图的NSTableView中轻松地控制(可能在一个单元格中与其他控件一起)第一个响应者单击?

解决方案

要解决此问题,请在NSTableView上覆盖此方法:

  @interface NSResponder(NSControlEditingSupport)

/ *这是一个响应者链方法,允许控件确定他们应该成为第一个响应者。某些控件(如NSTextField)应该只在包含NSTableView / NSBrowser指示视图可以开始编辑时成为第一个响应者。它取决于想要验证的特定控件在其-mouseDown:(或其他时间)调用此方法,以确定它是否应该尝试成为第一个响应者。当没有-nextResponder时,默认实现返回YES,否则,它被转发到响应者链。 NSTableView / NSBrowser实现这一点,只有在响应者是所选行中的视图时才允许第一响应者状态。如果需要(可能)发送doubleAction,它还延迟第一响应者分配。如果没有适用的事件,事件可以为零。
* /
- (BOOL)validateProposedFirstResponder:(NSResponder *)responder forEvent:(NSEvent *)event NS_AVAILABLE_MAC(10_7);

@end

并立即返回YES,允许firstResponder快速制作。如果文本字段被命中,表延迟使第一响应者,并且不允许它,除非首先选择该行。


View-based NSTableViews seem to have just the standard behavior, where, in order to make a text field inside the table the first responder, the user has to either double click or to single click and "keep calm".

However, given the flexibility view-based NSTableViews offer, this behavior is not not always desirable since there are now much different and complex applications possible than just doing an "old school" table.

How can I easily make a control (possibly in a cell together with other controls) inside a view-based NSTableView the first responder by a single click?

解决方案

To solve this, override this method on 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

And return YES right away to allow the firstResponder to be made quickly. The table "delays" making the first responder if a text field was hit, and doesn't allow it to be made unless the row was selected first.

这篇关于在基于视图的NSTableView中,如何使控件第一个响应者单击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆