基于视图的 NSTableView 似乎只有标准行为,为了使表内的文本字段成为第一响应者,用户必须双击或单击并“保持冷静”。
然而,考虑到基于视图的 NSTableViews 提供的灵活性,这种行为并不总是可取的,因为现在可能有很多不同且复杂的应用程序,而不仅仅是做一个“老式”表。
如何通过单击轻松地使基于视图的 NSTableView 内的控件(可能与其他控件一起在单元格中)成为第一响应者?
要解决这个问题,请在 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
并立即返回 YES 以允许快速创建firstResponder。如果点击文本字段,该表会“延迟”创建第一响应者,并且除非首先选择该行,否则不允许创建第一响应者。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)