nscontrol

First responder on mouse down behavior NSControl and NSView

巧了我就是萌 提交于 2021-01-28 13:57:08
问题 I have a custom control. If it inherits from NSView , it automatically becomes the first responder when I click on it. If it inherits from NSControl , it does not. This difference in behavior persists, even if I override mouseDown(with:) and don't call super. Code: class MyControl: NSView { override var canBecomeKeyView: Bool { return true } override var acceptsFirstResponder: Bool { return true } override func drawFocusRingMask() { bounds.fill() } override var focusRingMaskBounds: NSRect {

ControlTextDidChange not working for setting string of NSTextField

强颜欢笑 提交于 2019-12-25 08:58:12
问题 I'm trying to find a method that monitors the text of NSTextField for changes. I tried the delegate method of -(void)controlTextDidChange:(NSNotification *)obj but it only works when the user types into the text field. If the text field string is programmatically set, such as with a button, the controlTextDidChange doesn't work. Is there a method or another approach that I can use to monitor the contents of a NSTextField for changes? My ButtonText class (set as delegate for the NSTextField):

In OS X 10.10, can I implement an NSControl without an NSCell?

社会主义新天地 提交于 2019-12-20 12:41:14
问题 I am learning about NSControl . I am aware that NSCell has begun its road to deprecation in OS X 10.10 Yosemite, and so I'd rather not use an API that is going away. Also, the NSControl Class Reference shows all cell accessors have been deprecated. I understand all this, but what is not as clear is what the recommended course is for people writing NSControl subclasses on 10.10. All of the Apple guides on the subject make no mention of the deprecation of NSCell . I suppose I could just do

How to catch some events on a NSControl in swift

六月ゝ 毕业季﹏ 提交于 2019-12-18 09:53:12
问题 I am writing an application for OSX in Swift and I am looking for a good way to catch events on a NSControl. Obviously, I searched but the informations I found are often unclear or old. In my case, I would like to catch several events on a NSTextField (key up, text changed, focus lost,...). When I push on “Enter” in the NSTextField, it sends an action. Maybe is there a way to send an action when I click or write in the NSTextField? 回答1: You can subclass NSTextField and override textDidChange

How to catch some events on a NSControl in swift

梦想与她 提交于 2019-12-18 09:52:38
问题 I am writing an application for OSX in Swift and I am looking for a good way to catch events on a NSControl. Obviously, I searched but the informations I found are often unclear or old. In my case, I would like to catch several events on a NSTextField (key up, text changed, focus lost,...). When I push on “Enter” in the NSTextField, it sends an action. Maybe is there a way to send an action when I click or write in the NSTextField? 回答1: You can subclass NSTextField and override textDidChange

In a view-based NSTableView, how make a control the first responder with a single click?

半腔热情 提交于 2019-12-12 08:39:50
问题 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

What method should I call on my NSCell

纵然是瞬间 提交于 2019-12-11 02:21:31
问题 I am writing a custom NSControl with custom NSCells. It is a control, so it has to respond to the mouse. I created an NSTrackingArea over my control, implemented -mouseEntered: , -mouseExited: and -mouseMoved: . (And I will have to implement -mouseUp/Down: , but I have no idea what to do in there, so for now I haven't overridden those methods yet.) In these methods I successfully determine on which cell the mouse currently is. Now I have two questions: Is this a good approach for tracking the

NSControl isEnabled only available in OS X v10.0 through OS X v10.9

空扰寡人 提交于 2019-12-11 01:54:58
问题 Does anybody know why NSControl's isEnabled has been removed while setEnabled: is still working? 回答1: In OS X 10.10 (and iOS 8), many of the getter/setter method pairs in Apple's frameworks were replaced by @property declarations. This both makes the header interface clearer and makes the import of those APIs into Swift more... well, Swifty. // Before - (BOOL)isEnabled; - (void)setEnabled:(BOOL)enabled; // After @property(getter=isEnabled) BOOL enabled The documentation hasn't been fully

NSTextField autocompletion delegate method not called

时光怂恿深爱的人放手 提交于 2019-12-06 22:34:07
问题 I implemented the following delegate method for NSTextField to add autocompletion support: - (NSArray *)control:(NSControl *)control textView:(NSTextView *)textView completions:(NSArray *)words forPartialWordRange:(NSRange)charRange indexOfSelectedItem:(NSInteger *)index The issue is that this method never gets called. I can verify that the delegate of the NSTextField is set properly because the other delegate methods function as they should. 回答1: You'll need to get complete: called on the

NSTextField autocompletion delegate method not called

老子叫甜甜 提交于 2019-12-05 03:50:40
I implemented the following delegate method for NSTextField to add autocompletion support: - (NSArray *)control:(NSControl *)control textView:(NSTextView *)textView completions:(NSArray *)words forPartialWordRange:(NSRange)charRange indexOfSelectedItem:(NSInteger *)index The issue is that this method never gets called. I can verify that the delegate of the NSTextField is set properly because the other delegate methods function as they should. You'll need to get complete: called on the text field's field editor at some point. That's what triggers the completions menu, but it doesn't get called