NSTextfield stringValue

Discussion in 'Mac Programming' started by Surge963, Jun 7, 2014.

  1. Surge963 macrumors newbie

    Joined:
    Jun 7, 2014
    #1
    Hey guys,

    I'm an extremely novice programmer and have run into an issue. I've been looking around for a while looking for a solution, but my code seems sound.

    Basically I'm trying to grab the text from an NSTextField and make it into a string. I have used:

    NSString *_mystring = [_mytextfield stringValue];

    I also have:

    @property (nonatomic, retain) NSString *mystring;

    in the .h

    I know the code works because I set a log to show the _mystring value after a button click, and nothing shows up even after typing in the textfield. I have found that if I change the name of the textfield within the .xib file the name shown in the log as the string value.

    I wanted the string value to be anything typed into the textfield.

    Any insight?
     
  2. Paulie87 macrumors newbie

    Joined:
    Mar 2, 2014
  3. Surge963 thread starter macrumors newbie

    Joined:
    Jun 7, 2014
    #3
    I get the error:

    property 'text' not found on object of type 'NSTextField'
     
  4. Paulie87 macrumors newbie

    Joined:
    Mar 2, 2014
    #4
    Just noticed this was mac and not ios forum. You're declaring your property in .h then re declaring it,

    Try
    mystring = [mytextfield stringValue];

    Also is your textfield connected to an IBOutlet? I don't have any experience developing for osx mainly from an ios background :)
     
  5. Surge963 thread starter macrumors newbie

    Joined:
    Jun 7, 2014
    #5
    Yes, my textfield is connect to an IBOutlet. This did fix a problem with an Array I had later in my code :D, but the string value is still unable to be changed from the UI. It remains either " " when nothing is in the field, or "Test" when the title of the field is Test.
     
  6. xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #6
    Haven't done much OS X coding for a while. I would have thought the default would be to allow editing and selection. Check out
    Code:
    - (void)setEditable:(BOOL)flag
     
  7. Surge963 thread starter macrumors newbie

    Joined:
    Jun 7, 2014
    #7
    Figured this out a couple hours ago. I was just being dumb. I only grabbed the textfield stringvalue upon the applicationDidFinishLaunching. I simply moved the code to an action. As always the code was was only doing what I was telling it to.
     

Share This Page