 |
 |
Odd nil problems with GUI connections
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: Norfolk, Va
Status:
Offline
|
|
I have a window with an NSTextField in it connected to my controller object. But at applicationDidFinishLoading: when I try to setStringValue:@"Hello!" the textfield, it does nothing. Upon debugging, it's showing textField as nil.
Any ideas?
|
|
you are not your signature
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
Originally posted by Gametes:
I have a window with an NSTextField in it connected to my controller object. But at applicationDidFinishLoading: when I try to setStringValue:@"Hello!" the textfield, it does nothing. Upon debugging, it's showing textField as nil.
Any ideas?
Make sure that the name of your outlet in IB is the same thing as your name in PB. If you're not already, I'd suggest using IBOutlet before you declare instance variables and IBAction as the return type for instance methods so that you can use IB to read the header files and create the outlets and actions for you, avoiding the problem where you needed an outlet or method one thing in your header file and something else in IB.
If that's not your problem, I'd probably have to look at your code to figure it out.
Hope this helps,
Matt Fahrenbacher
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status:
Offline
|
|
If your outlet is named something like "widget" and the class you're connecting it to has a method named "setWidget:", that will be called automatically to connect the outlet. If your setWidget: method is meant to do something completely different, the outlet won't be connected.
This has happened to me a few times. For example, say that you're subclassing NSButton so that it'll stay synced with some NSTextField that contains the title of your document. You give your NSButton subclass a 'title' outlet and connect it to whatever.
Well, it never gets connected because NSButton responds to setTitle, and that gets called to set the outlet.
This can be a bitch to track down.
|
Geekspiff - generating spiffdiddlee software since before you began paying attention.
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: Norfolk, Va
Status:
Offline
|
|
It's the stragest thing really. I've deleted, renamed, reimported, and reconnected all of these things and still no go.
On top of this, my userdefaults won't write!
NSUserDefaults *defaults = [[NSUserDefaults standardUserDefaults] retain];
[defaults setObject:@"Yo" forKey:@"Momma"];
nuthin shows up in the save file except my toolbar setup and some audio preference?!
|
|
you are not your signature
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
1. Have you tried calling synchronize?
2. It isn't really necessary to retain the standardUserDefaults object. It's not going anywhere.
|
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
Originally posted by Chuckit:
1. Have you tried calling synchronize?
2. It isn't really necessary to retain the standardUserDefaults object. It's not going anywhere.
1. What Chuckit is saying is that defaults don't get written out to file every time you add data to the defaults dictionary in active memory. It usually gets written out every 5 minutes, and it also gets written out when your application quits. So either quit your application or synchronize your defaults (which writes out the defaults now) and then you should be good to go. If not, then your system does have some serious problems, and I would suggest a reboot - that's fixed problems for me when things like the Font Server crash.
2. Well, it depends if he wants to keep a reference to it for later on. Although the shared instance will probably stick around because [NSUserDefaults sharedUserDefaults] probably returns a non-autoreleased object, I still think it's good programming style to retain stuff when it's passed to you and autorelease it when you're done with it (assuming that you're holding on to the object for some period of time).
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: Norfolk, Va
Status:
Offline
|
|
I retain it because I use it in loadPrefs and savePrefs methods which get called before riskier operations 
In savePrefs I have [prefs synchronize], so yes it's there. I dunno, I guess I'll reboot. But are there cases where changing bundle identifiers and stuff after you creat the project has caused this problem? Maybe I've forgotten some step somewhere?
Wait, stop the presses! The defaults problem is fixed, who knows how. now about that lame connection... 
|
|
you are not your signature
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
Without the source, this is going to be hard to debug...
Matt Fahrenbacher
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|