このサイトで見つけた多くの可能性を試し、アップルの開発者ページからいくつかの説明を読みましたが、NSViewController with/form NIB のロードに関する問題を解決できなかったようです。
Xcode プロジェクトのファイルは次のようになります。
- SecondViewController.h
- SecondViewController.m
- SecondViewController.xib
- AppDelegate.h
- AppDelegate.m
- MainMenu.xib
主な問題は、SecondViewController.xib の初期 nib を使用して SecondViewController をプログラムで作成する方法です。
- MainMenu.xib の FileOwner のカスタム クラスは NSApplication です。
- SecondViewController.xib の FileOwner のカスタム クラスは SecondViewController です。
- MainMenu.xb にはいくつかのパネルとウィンドウがあります (ウィンドウと設定パネルについて)
- このアプリケーションにはメイン ウィンドウがありません (ステータス バーの通知アイコンを使用)
SecondViewController.h
@interface SecondViewController : NSViewController {
BOOL fullScreenMode;
NSImageView *fullScreenbg;
NSImageView *imageView1;
NSImageView *imageView2;
NSPanel *imageWindow;
}
@property (assign) IBOutlet NSImageView *fullScreenbg;
@property (assign) IBOutlet NSImageView *imageView1;
@property (assign) IBOutlet NSImageView *imageView2;
@property (assign) IBOutlet NSPanel *imageWindow;
SecondViewController.m
@implementation SecondViewController {
NSImageView *nv1;
NSImageView *nv2;
NSSize curImgSize;
}
@synthesize fullScreenbg;
@synthesize imageView1;
@synthesize imageView2;
@synthesize imageWindow;
......
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Initialization code here.
fullScreenMode = YES;
}
return self;
}
AppDelegate.h
@interface AppDelegate : NSObject <NSApplicationDelegate,NSWindowDelegate> {
NSPanel *aboutWindow;
IBOutlet NSMenu *myStatusMenu;
IBOutlet NSMenuItem *toggleFullScreen;
}
AppDelegate.m
@implementation AppDelegate {
SecondViewController *controller;
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
controller = [[SecondViewController alloc]
initWithNibName:@"SecondViewController"
bundle:nil];
//Not work (fullscreenbg, imageView1, imageView2,imageWindow = nil)
//controller = [[SecondViewController alloc] init]; ?? <-- didn't work either
}
initWithNibName または単に init を使用している場合でも、すべての IBOutlet プロパティがデバッグ時に nil のように見えます。
「NSBundle loadNibNamed」やloadViewを使用するなどの他の解決策を試しましたが、うまくいきませんでした(警告メッセージ:「NSObjectはloadViewに応答しません」)。
secondViewController の主な目的は、グラフィックや Web 要素を含む通知メッセージを表示することです。
誰かが私に最高の提案をしてくれることを願っています。ありがとう。