2016-08-06 4 views
0

끌어서 놓을 수있는 NSDocuments 리소스가 들어있는 보조 창을 추가하고 싶습니다.문서 기반 응용 프로그램에 보조 창을 추가하는 방법

내 프로젝트에는 다음이 포함

1) ResourceWindow.xib에게

2) ViewController.xib을

3) Main.storyboard

@interface AppDelegate() 


@property (nonatomic,strong)NSWindowController* wc; 
@property (nonatomic, weak)NSWindow* resourceWindow; 
@property (nonatomic, strong)ViewController* vc; 


@end 

@implementation AppDelegate 

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification 
{ 

    self.wc = [[NSWindowController alloc]initWithWindowNibName:@"ResourceController.xib"]; 
    self.resourceWindow = [self.wc window]; 
    [self.wc showWindow:self]; 
    self.vc = [[ViewController alloc]initWithNibName:nil bundle:nil]; 
    [self.vc.view setFrame:[self.resourceWindow.contentView bounds]]; 
    [self.resourceWindow.contentView addSubview:self.vc.view]; 
} 

self.wc.window 즉시 전무하다 그것을 할당하고 초기화 한 후에

나를 바로 설정하십시오.

감사

편집 :

ResourceWindow.xib이 창 컨트롤러를 그냥 창을 포함하지 않습니다. 그게 문제 야? 사용자 정의 객체를 xib 파일로 드래그 앤 드롭하고 클래스를 NSWindowController로 변경하는 솔루션입니까?

+0

ResourceWindow.xib의 파일 소유자는 창에 연결된 창 컨트롤러 여야합니다. 그리고 "ResourceWindow.xib"≠ "ResourceController.xib". – Willeke

답변

0

Willeke가 지적한 파일 이름 문제 외에도 showWindow가 호출 될 때까지는 윈도우가 nil입니다. 한숨. NSWindowManager를 하위 클래스로 만들고 xib 파일을 추가하여 검사를 다시 시작했습니다. 그런 다음 파일 소유자를 SourceWindowController로 설정하고 코드를 다음과 같이 변경합니다.

@property (nonatomic,strong)SourceWindowController* wc; 
@property (nonatomic, weak)NSWindow* resourceWindow; 


@end 

@implementation AppDelegate 

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification 
{  
    self.wc = [[SourceWindowController alloc]initWithWindowNibName:@"SourceWindowController"]; 
    [self.wc showWindow:self.window]; 
    self.resourceWindow = [self.wc window]; 
+0

'window'가 호출 될 때까지 창은 nil입니다. 'showWindow'는'window'를 호출합니다. '[self.wc showWindow : self.window]의 보낸 사람'self.window'는 이상합니다. – Willeke