Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Loading preferences into NSTextField crash..

Loading preferences into NSTextField crash..
Thread Tools
Grizzled Veteran
Join Date: Jun 2002
Status: Offline
Reply With Quote
Apr 24, 2004, 03:01 PM
 
Hey guys,

I've got a text field, and in it I want it to save the data when I click a button.

I do this code when I click a button:

Code:
[[NSUserDefaults standardUserDefaults] setObject:[codeTextField stringValue] forKey:@"RegistrationCode"];
And in awakeFromNib I do this code to load what was in the text field back in:

Code:
[codeTextField setStringValue:[[NSUserDefaults standardUserDefaults] stringForKey:@"RegistrationCode"]];
But for some reason, I get this weird crash on startup, here is what it says:

2004-04-24 21:01:12.914 Tag[4392] *** Assertion failure in -[NSTextFieldCell _objectValue:forString:], AppKit.subproj/NSCell.m:1131
2004-04-24 21:01:12.925 Tag[4392] An uncaught exception was raised
2004-04-24 21:01:12.931 Tag[4392] Invalid parameter not satisfying: aString != nil
2004-04-24 21:01:12.938 Tag[4392] *** Uncaught exception: <NSInternalInconsistencyException> Invalid parameter not satisfying: aString != nil

«PROJECTNAME» has exited due to signal 5 (SIGTRAP).

I am totally at lost here, as I get no warnings or errors when building, any ideas appreciated .

Thanks,
Oliver
     
Grizzled Veteran
Join Date: Jun 2002
Status: Offline
Reply With Quote
Apr 24, 2004, 04:36 PM
 
apparently, I need to check if my preferences are nil, but Im not sure how to do this? Any ideas?
     
Senior User
Join Date: Aug 2002
Location: Oxford, England
Status: Offline
Reply With Quote
Apr 25, 2004, 06:17 AM
 
Maybe something like this...

Code:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSString *regCode = [defaults stringForKey:@"RegistrationCode"]; //Check to see if regCode is nil, then set regCode as a default value if (regCode == nil) regCode = @""; [codeTextField setStringValue:regCode]; //or //Check to see if regCode is nil, then perform an action if (regCode == nil) { NSLog(@"Registration code is nil."); } else { [codeTextField setStringValue:regCode]; }
(Tags looking great by the way )
(Last edited by sandsl; Apr 25, 2004 at 06:23 AM. )
Luke
     
Grizzled Veteran
Join Date: Jun 2002
Status: Offline
Reply With Quote
Apr 25, 2004, 07:29 AM
 
Originally posted by sandsl:
Maybe something like this...

Code:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSString *regCode = [defaults stringForKey:@"RegistrationCode"]; //Check to see if regCode is nil, then set regCode as a default value if (regCode == nil) regCode = @""; [codeTextField setStringValue:regCode]; //or //Check to see if regCode is nil, then perform an action if (regCode == nil) { NSLog(@"Registration code is nil."); } else { [codeTextField setStringValue:regCode]; }
(Tags looking great by the way )
Thanks for the Tag comment and code :-) Works great.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:10 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2