Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Surge963

macrumors newbie
Original poster
Jun 7, 2014
4
0
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?
 
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 :)
 
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 :)

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.
 
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
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.