How do you set the text in an NSTextField?

2019-01-22 10:34发布

I'm trying to set the text in an NSTextField, but the -setStringValue: and -setTitleWithMnemonic: methods are not working. Any ideas?

6条回答
虎瘦雄心在
2楼-- · 2019-01-22 10:47

setStringValue: is the way to do it. You should make sure your outlet is being set properly. (In the debugger, make sure your textfield variable is not null.)

查看更多
可以哭但决不认输i
3楼-- · 2019-01-22 10:56

Just myLabel.stringValue = "MY TEXT" works here, using Swift and Xcode 6.

查看更多
一夜七次
4楼-- · 2019-01-22 11:02

just do this

[textField setString:@"random"];
查看更多
Melony?
5楼-- · 2019-01-22 11:05

Swift 4

self.yourTextField.stringValue = "Your_Value"

Note: Fetching value from self.yourTextField.stringValue at that will get warning message i.e. Warning Message To avoid this kind of warning you can use like this (suggested way)

DispatchQueue.main.async {
 your code ... 
} 

OR also refer to this.

查看更多
闹够了就滚
6楼-- · 2019-01-22 11:05

ObjectiveC:

[label setStringValue: @"I am a label"];

original code I use in my code to display application version is:

    [lblVersion setStringValue:[NSString stringWithFormat:@"v%@", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]]];
查看更多
The star\"
7楼-- · 2019-01-22 11:13

Just do something like this:

myLabel.stringValue = @"My Cool Text";
查看更多
登录 后发表回答