Ray's playground

 

Nib Files and NSWindowController(Chapter 12 of Cocoa Programming for Mac OS X)

PreferenceController
 1 #import "PreferenceController.h"
 2 
 3 
 4 @implementation PreferenceController
 5 
 6 - (id)init
 7 {
 8     if(![super initWithWindowNibName:@"Preferences"])
 9     {
10         return nil;
11     }
12     
13     return self;
14 }
15 
16 - (void)windowDidLoad
17 {
18     NSLog(@"Nib file is loaded");
19 }
20 
21 - (IBAction)changeBackgroundColor:(id)sender
22 {
23     NSColor *color = [colorWell color];
24     NSLog(@"Color changed: %@", color);
25 }
26 
27 - (IBAction)changeNewEmptyDoc:(id)sender
28 {
29     int state = [checkbox state];
30     NSLog(@"Checkbox changed %d", state);
31 }
32 
33 @end

 

AppController
 1 #import "AppController.h"
 2 #import "PreferenceController.h"
 3 
 4 @implementation AppController
 5 
 6 - (IBAction)showPreferencePanel:(id)sender
 7 {
 8     if(!preferenceController)
 9     {
10         preferenceController = [[PreferenceController alloc] init];
11     }
12     NSLog(@"showing %@", preferenceController);
13     [preferenceController showWindow:self];
14 }
15 
16 @end

 

 

posted on 2011-02-21 17:25  Ray Z  阅读(258)  评论(0编辑  收藏  举报

导航