Cocoa and user preferences question

7 views
Skip to first unread message

Jon M. Hanson

unread,
May 19, 2011, 12:45:02 AM5/19/11
to xcodep...@googlegroups.com
I'm learning Cocoa and I'm up to a chapter regarding user preferences. I have a preference panel, whose nib is loaded and I read the user preferences file I've created. The preference panel consists of a checkbox and a color well. My user preference for the check box is returning false but yet the check box is checked when the preference panel is opened. In the NSLogs below print out that emptyDocument is false. The checkbox variable is an outlet for the PreferenceController class. Should I not be using setState to set or clear the checkbox? Below is the code snippet from PreferenceController.m:

- (id)initWithWindow:(NSWindow *)window
{
    self = [super initWithWindow:window];
    if (self) {
        // Initialization code here.
        [colorWell setColor: [self tableBackgroundColor]];
        NSLog(@"emptyDocument will return %d", [self emptyDocument]);
        [checkbox setState: [self emptyDocument]];
    }

    

    return self;
}

-(BOOL) emptyDocument
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    

    NSLog(@"Returning %d for EmptyDocumentFlag", [defaults boolForKey:@"EmptyDocumentFlag"]);
    return ([defaults boolForKey:@"EmptyDocumentFlag"]);
}

---
Jon M. Hanson (N7ZVJ)




Jiva DeVoe

unread,
May 19, 2011, 1:31:57 AM5/19/11
to xcodep...@googlegroups.com
Your outlets aren't connected yet in the initializer.  Use awakeFromNib or windowDidLoad to set this stuff up.
--
You received this message because you are subscribed to the Google Groups "XCodePhoenix" group.
To post to this group, send email to xcodep...@googlegroups.com.
To unsubscribe from this group, send email to xcodephoenix...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/xcodephoenix?hl=en.

--
Jiva DeVoe
iZen Garden & Edibles - iPhone software for your mind and body.

Jon M. Hanson

unread,
May 19, 2011, 10:57:31 AM5/19/11
to xcodep...@googlegroups.com
I moved the code in question to windowDidLoad but I'm still seeing the same result. If I put a breakpoint in windowDidLoad on the call to set the checkbox state it will not fire when I open the preferences window. Likewise I get no output from NSLog calls in there. I think I probably had the calls in there to begin with but when it didn't work and I couldn't get a breakpoint to work in there I tried something else.

---
Jon M. Hanson (N7ZVJ)




Jiva DeVoe

unread,
May 19, 2011, 1:21:45 PM5/19/11
to xcodep...@googlegroups.com
Read the docs on windowDidLoad and awakeFromNib and choose the right one. awakeFromNib may be what you want.

Jon M. Hanson

unread,
May 20, 2011, 12:46:35 AM5/20/11
to xcodep...@googlegroups.com
awakeFromNib did the trick. Thank you for the help.

---
Jon M. Hanson (N7ZVJ)




On May 18, 2011, at 10:31 PM, Jiva DeVoe wrote:

Reply all
Reply to author
Forward
0 new messages