How do you set the text in an NSTextField?

前端 未结 7 2186
孤城傲影
孤城傲影 2020-12-08 12:39

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

相关标签:
7条回答
  • 2020-12-08 12:59

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

    0 讨论(0)
  • 2020-12-08 13:09

    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"]]];
    
    0 讨论(0)
  • 2020-12-08 13:14

    just do this

    [textField setString:@"random"];
    
    0 讨论(0)
  • 2020-12-08 13:15

    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.)

    0 讨论(0)
  • 2020-12-08 13:20

    If the value you're trying to set happens to be an integer rather than a string, you don't need to convert the integer value to a string manually; you can just call:

    myLabel.integerValue = i;
    

    The integerValue property is defined on NSTextField's parent class, NSControl. See that linked documentation page for a full list of methods it supports.

    0 讨论(0)
  • 2020-12-08 13:22

    Just do something like this:

    myLabel.stringValue = @"My Cool Text";
    
    0 讨论(0)
提交回复
热议问题