This is the latest incarnation of my weblog. Feel free to poke around.
This website has no relationship with The Inn at Rancho Santa Fe (and neither do I).
I'm sure this question has been addressed by now, but seriously, WTF?
This is the latest incarnation of my weblog. Feel free to poke around.
This website has no relationship with The Inn at Rancho Santa Fe (and neither do I).
Are you, by chance, the Russell Finn that ported Pirates! to the Macintosh in the late 80s? If, so, I have some questions for you.
Are you, by chance, the Russell Finn that ported “Silent Service” to Amiga in the 1980s? If, so, I have some questions for you related to submarine simulation models precision development over time (Silent Service, Silent Hunter, Wolfpack, UBoat, …)
I am, but I’m afraid I won’t be much help for you; that was a long time ago, and my focus was on the technical challenges of porting existing software to a new 16-bit system, rather than on the details of simulating submarines in an 8-bit game — that would have been Sid Meier’s work.
Ah, you ARE! A well-built LinkedIn profile for the win!
I am a part of an informal group of Mac preservationists dedicated to recording the history of Mac software in the 68k days. I was hoping you’d be willing to answer some questions about the projects you worked on for MicroProse. If you are, shoot me an e-mail at arthegall@gmail.com. Thanks.
David
Hi, yes, that’s me. Gee, that was a long time ago… I’ll shoot you an email this weekend.
Hi Russell
I stumbled across your blog while researching what I thought would be a simple thing but can’t find a solution. As a self taught programmer in Swift I have written a couple of iOS apps and learnt a lot but struggling with my first macOS app which includes a NSTextField. All I want to do is when user clicks inside the text field an action func runs. I have tried NSTextField and NSTextFieldcell but don’t understand how it should work, any poiters would be useful.
Hi, Andrew —
The answer to your question depends somewhat on whether your text field is editable or not.
If the text field is not editable, it’s pretty straightforward — since NSTextField inherits from NSControl, it has a
mouseDown(_:)
method. By default a non-editable NSTextField does not respond to mouse clicks, but it’s easy to write a subclass that does:(I’ve used
self
explicitly here to call out the method and properties that are already present on an NSControl.)Once you have this class in your code, you can create an NSTextField in Interface Builder, change its class to ClickableTextField in the Identity Inspector, and then set up a class to act as the delegate of the NSTextField and implement an action method. Typically this would be a controller class already in your app (perhaps the window controller for the window that contains your text field). Then assign the
delegate
andaction
properties of the text field in Interface Builder, and you’re done.If the text field is intended to be editable, then things get more complicated. In this case, the NSTextField already responds to a mouse down event by setting up the field editor — a single NSTextView shared among all the text fields in a window. Once the text field is active, all the mouse clicks go to the NSTextView as part of the editing session. If it’s actually your intention to monitor these mouse clicks, then you probably have a lot more work to do (for a sense of how much, see the Apple documentation for the Cocoa text architecture, specially the section titled “Working with the Field Editor”). I would suggest considering what your actual goal is; if you find yourself fighting with AppKit, there’s usually a different/better way to accomplish your goal.
Hope this helps. Thanks for dropping by.
Hi Russell
Just found your detailed reply so thanks very much for that. I do need the textfield to be editable and have read thru the Apple documents you linked to but got hopelessly lost. I can populate the text field by double clicking on a table cell or just by clicking in the text field itself but do a question. I have for testing purposes created 2 text fields, one NSTextfield and a NSTextfieldcell but don’t know what the differences are. Ideally I would like to know when user clicks in textfield AND update the character counter as they type I am using:- imputTextFieldCell.accessibilityNumberOfCharacters(). Can you please suggest a tutorial or example that might help me as I can find very little for macOS apps?
Andrew
Andrew —
Let me try to point you to some resources that may help you.
accessibilityNumberOfCharacters
is probably not the best way to count the characters in the text field; instead, you can “bind” a variable in your application (usually a property in your window or view controller) to the expression “inputTextField.string.length”, and the variable will then be updated for you whenever the string is edited. You can then bind the string value of another text field to that variable, and it will display the character count. (This may make more sense after you read the linked article.)I hope this helps. Good luck.