ヒレガス本 12章 課題

課題は、NSBundleを利用してnibをロードし独自のAboutPanelを表示しろとの事。

早速NSBundleを使ってNibをロードしようと、

[NSBundle loadNibNamed: owner:]

を使おうとしたらDeprecatedとの事。

仕方が無いので、NSNibを使用して以下のように書いた。

- (IBAction) showAbouPanel:(id)sender
{
    if( !aboutPane )
    {
        NSNib*    theAboutPanelNib;

        theAboutPanelNib = [[NSNib alloc] initWithNibNamed:@"aboutPanel.nib"
                                                    bundle:nil];

        NSArray* theTopLevelObject;

        if( [theAboutPanelNib instantiateWithOwner:self
                                      topLevelObjects:&theTopLevelObject] )
        {
            NSLog(@"aboutPanel loaded from nib. %@", theTopLevelObject);

        }
    }

    [aboutPane makeKeyAndOrderFront:sender];
}

プロジェクトファイルは、 RaiseMan_NibAndWindowController に置いておきます。