2014-01-24 3 views
0

나는 프로그래밍/코코아 학습의 초기 단계에 있으며, 간단한 UI를 프로그래밍 방식으로 작성하여 코드/GUI 간의 관계를보다 잘 시각화하기로 결정했습니다. 지금까지 템플릿에 OS X의에서 내 유일한 수정 코코아의 기본 템플릿을 열 수 있습니다 Appdelegate.m에서 Appdelegate.h 에서NSWindow의 인스턴스를 프로그래밍 방식으로 NSWindow에 추가하기

@property NSButton *theButton; 

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification 
{ 
    CGRect buttonFrame; 

    buttonFrame = CGRectMake(20, 20, 15, 5); 
    self.theButton = [[NSButton alloc]initWithFrame:buttonFrame]; 
    [self.theButton setTitle:@"test"]; 
    [self.window addSubview:self.theButton]; 


} 

합니다. 왜이

[self.window addSubview:self.theButton];

No visible @interface for 'NSWindow' declares the selector 'addSubview:'

입니다 :

그러나 나는 오류는 무엇입니까?

+0

'self.window.view'입니까? – nhgrif

답변

1

NSWindow에는 addSubview : 메소드가 없기 때문에. 그 방법은 NSView의 일부입니다. 창의 contentView를 원할 수 있습니다. NSWindow 표시가 NSResponder에 상속

+0

감사합니다. 나는 그것이 IOS와는 조금 다르다고 생각한다. iOS에서 수행 한 자습서에서는 [self.window addSubview : self.taskTable]을 사용하여 동일한 작업을 수행했습니다. 그러므로 혼란 – PopKernel

+1

iOS의 UIWindow는 addSubview를 가지고 있지만, 거의 사용해서는 안된다는 점을 지적하고 싶습니다. 당신은 여전히 ​​어떤 종류의 UIView에 버튼이나 뷰를 추가하고자 할 것입니다. 일반적으로 rootViewController의 뷰입니다. –

4

은 그래서 당신은 사용할 수 있습니다

[self.window.contentView addSubview: yourbutton];

좋아하지만 당신이 사용할 수있는 UIWindow합니다. UIView에서 상속되기 때문에 [self.window addSubview:button]입니다. 희망은 더 분명해질 것입니다 ...

관련 문제