2012-08-09 5 views
0

프로그래밍 방식으로 NSView에 NSTableView를 추가하는 데 문제가 있습니다. 뷰는 NSSplitView의 첫 번째 뷰입니다. 내 포인터는 바로 설정되어 있습니다. NSButton을 뷰에 추가해도 아무런 문제가 없으므로 확실합니다. 또한 내 tableview의 대리자 및 데이터 소스 메서드가 예상대로 작동합니다. 내보기에 테이블보기를 추가하려면 인터페이스 작성기를 사용하면 작동합니다. 그러나 IB 사용을 원하지 않습니다. 코드를 통해이 작업을 수행하고 싶습니다. 다음은 현재 사용중인 코드입니다. 내가 버튼을 주석 경우의 tableview이 나타나지 않지만NSView에 NSTableView를 프로그래밍 방식으로 추가하기

-(void)awakeFromNib{ 


    tableData = [[NSMutableArray alloc]initWithObjects:@"March",@"April",@"May", nil]; 


    tableView = [[NSTableView alloc]initWithFrame:firstView.frame]; 



    [tableView setDataSource:self]; 
    [tableView setDelegate:self]; 



    [firstView addSubview:tableView]; 

    NSButton *j = [[NSButton alloc]initWithFrame:firstView.frame]; 
    [j setTitle:@"help"]; 

    [firstView addSubview:j]; 




} 

NSButton 객체가 화면에 나타납니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까. 도와 주셔서 감사합니다.

+0

은 tableView 속성이며, 그렇다면 strong (또는 retain)으로 선언되어 있습니까? – rdelmar

+0

tableview는 @property (nonatomic, retain) NSTableView * tableView;로 선언 된 속성입니다. – xMythicx

+0

이 프로젝트에서 ARC 기능을 해제했습니다 – xMythicx

답변

4

감사합니다. 도움을 받아서 고맙습니다. IB는 자동으로 테이블 뷰 주위에 NSScrollview를 삽입하고 열을 삽입합니다. 코드에서이 작업을 수행하려면 스크롤보기와 열을 할당해야합니다. 다른 사람들이이 문제를 우연히 만난다면 내가 현재 활용하고있는 것이 있습니다.

-(void)awakeFromNib{ 

    tableData = [[NSMutableArray alloc]initWithObjects:@"March",@"April",@"May", nil]; 

    NSScrollView * tableContainer = [[NSScrollView alloc] initWithFrame:firstView.bounds]; 

    //This allows the view to be resized by the view holding it 
    [tableContainer setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; 

    tableView = [[NSTableView alloc] initWithFrame:tableContainer.frame]; 
    [tableView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; 
    NSTableColumn *column =[[NSTableColumn alloc]initWithIdentifier:@"1"]; 
    [column.headerCell setTitle:@"Header Title"]; 


    [tableView addTableColumn:column]; 



    [tableView setDataSource:self]; 
    [tableView setDelegate:self]; 


    [tableContainer setDocumentView:tableView]; 

    [firstView addSubview:tableContainer]; 

    //You mentioned that ARC is turned off so You need to release these: 
    [tableView release]; 
    [tableContainer release]; 
    [column release]; 


} 

도움 주셔서 감사합니다.

1

NSTableView은 기본적으로 NSScrollView입니다. 이렇게하면 다음과 같이 할 수 있습니다.

tableData = [[NSMutableArray alloc] initWithObjects:@"March",@"April",@"May", nil]; 

NSScrollView * tableContainer = [[NSScrollView alloc] initWithFrame:firstView.frame]; 
tableView = [[NSTableView alloc] initWithFrame:firstView.frame]; 

[tableView setDataSource:self]; 
[tableView setDelegate:self]; 

[tableContainer setDocumentView:tableView]; 

[firstView addSubview:tableContainer]; 

//You mentioned that ARC is turned off so You need to release these: 
[tableView release]; 
[tableContainer release]; 
+0

답변 해 주셔서 감사합니다. 기본적으로 테이블 뷰가 스크롤 뷰에 의해 캡슐화되지 않은 이유를 설명 할 수 있습니까? 왜 테이블 뷰 alloc 메소드가 충분하지 않은 것일뿐 아니라 열과 행을 만들어야합니까, 아니면 나를 위해 생성 된 것입니까? – xMythicx

+0

@xitzxmythicx NSScrollView에 빈 NSTableView를 만드는 모든 것을 만들어야합니다. –

관련 문제