I have an NSTextField
and I need to get the field's value into a variable. What's the appropriate method?
相关问题
- Xcode debugger displays incorrect values for varia
- Is there a way to report errors in Apple documenta
- Advice for supporting both Mac and Windows Desktop
- Avoid cmake to add the flags -search_paths_first a
- NSOutlineView drag line stuck + blue border
相关文章
- 现在使用swift开发ios应用好还是swift?
- Visual Studio Code, MAC OS X, OmniSharp server is
- xcode 4 garbage collection removed?
- IntelliJ IDEA can't open projects or add SDK o
- Automator: How do I use the Choose from List actio
- ImportError: No module named twisted.persisted.sty
- How can I vertically align my status bar item text
- Converting (u)int64_t to NSNumbers
Swift 3.x Version:
[myField stringValue]
NSTextField
inherits fromNSControl
, andNSControl
defines thestringValue
/setStringvalue:
methods.For an
NSString
you would use:For an
int
you would use:There are many other methods for getting the value from a control. Have a look at the
NSControl
reference for more info, under the "Getting and Setting the Control’s Value" section.Here's a list:
doubleValue
floatValue
intValue
integerValue
objectValue
stringValue
attributedStringValue
Also:
Say you have an object (
MyObject
) that wants to be be notified when someone types into aNSTextField
. In the .h file,MyObject
should declare it conforms toNSTextFieldDelegate
, as in...Then you set MyObject as the delegate of the
NSTextField
[myTextField setDelegate:myObject]
Now, you can find out when something happens in the textfield by implementing methods in MyObject like: