2011-08-14 12 views
0

多くの人が検索して試しましたが、2番目のウィンドウをアクティブにすることはできません。ウィンドウをアクティブにするには?

メインウィンドウがアクティブ化されている間、私は別のウィンドウを表示するために使用されるコード:

preferencesWindowController = (PreferencesWindowController*)[[NSWindowController alloc] initWithWindowNibName: @"Preferences"]; 
[preferencesWindowController showWindow: preferencesWindowController]; 
[[preferencesWindowController window] orderFrontRegardless]; 
[[preferencesWindowController window] makeKeyAndOrderFront: preferencesWindowController]; 
[NSApp activateIgnoringOtherApps:YES]; 

をデバッガを試した後は、私があるのはなぜ[preferencesWindowControllerウィンドウ]が

preferencesWindowController = (PreferencesWindowController*)[[NSWindowController alloc] initWithWindowNibName: @"Preferences"]; 
[preferencesWindowController showWindow: self]; 
NSWindow* window = [preferencesWindowController window]; //---> nil 

nilであることがわかりそれはない?


nibファイルには、WindowおよびPreferencesWindowControllerが含まれています。


申し訳ありませんが、私はマルチニブを間違えて使用しています。私はこの例に従い、動作させます:http://maestric.com/doc/mac/cocoa/multiple_nibs。 nibにウィンドウコントローラを追加する代わりに、ファイルのオーナークラスをウィンドウコントローラに設定する。

答えて

2

このコードは間違っている:PreferencesWindowControllerに結果をキャスト

preferencesWindowController = (PreferencesWindowController*)[[NSWindowController alloc] initWithWindowNibName: @"Preferences"]; 

が作成されたオブジェクトの種類を変更するつもりはありません。あなたが実際にあなたのペン先でファイルの所有者から窓に窓コンセントを接続したことを確認し、また

preferencesWindowController = [[PreferencesWindowController alloc] initWithWindowNibName: @"Preferences"]; 

:あなたは、オブジェクトの右の種類を作成する必要があります。

+0

nibファイルには、WindowおよびPreferencesWindowControllerが含まれています。 コードは役に立ちません。preferencesWindowControllerオブジェクトは、初期化後に0で埋められます。 – user486134

+0

あなたはジムの答えの2番目の部分を読みましたか? File's Ownerからあなたのペン先の窓に窓のコンセントを接続しましたか? –

+0

"また、実際には、ファイルの所有者のウィンドウコンセントをペン先のウィンドウに接続していることを確認してください。私の.xibには「File's Owner」があります。接続インスペクタで、ウィンドウに「新しい参照アウトレット」を選択できます。それはあなたが意味することですか?なぜそれが必要ですか?ウィンドウに永続的なリファレンスを作成すると、これに関係なく問題は解決されました。 – isgoed

関連する問題