테이블에 대한 NSTableViewDataSource를 만들어야합니다. 일반적으로 NSTableViewDataSource에서 상속 한 사용자 지정 클래스를 만든 다음이 메서드를 재정의합니다.
사용자 지정 Source 클래스의 인스턴스를 TableView의 DataSource 속성에 할당합니다. DataSource에는 데이터가 무엇이든간에 기반으로 채우는 내부 데이터 구조 (예 : List 또는 좀 더 복잡한 항목)가있을 것입니다. 그런 다음 등, 데이터의 길이에 따라 적절하게 대응할 수있는 데이터 소스 방법을 사용자 정의합니다
은의이 데이터는 간단한 문자열 []라고 가정하자 : 나는 믿고있어
// populate this in constructor, via service, setter, etc - whatever makes sense
private string[] data;
// how many rows are in the table
public int NumberOfRowsInTableView(NSTableView table)
{
return data.length;
}
// what to draw in the table
public NSObject ObjectValueForTableColumn (NSTableView table, NSTableColumn col, int row)
{
// assume you've setup your tableview in IB with two columns, "Index" and "Value"
string text = string.Empty;
if (col.HeaderCell.Title == "Index") {
text = row.ToString();
} else {
text = data [row];
}
return new NSString (text);
}
첫 번째 방법 반환하는 'table.RowCount'. 두 번째 방법을 설정하는 방법을 보여 주시겠습니까? – iwatakeshi
또는 C#을 제외하고는 다음과 같은 내용일까요? [Mac 용 Table View 프로그래밍 가이드] (https://developer.apple.com/library/mac/documentation/cocoa/Conceptual/TableView/PopulatingCellTables/PopulatingCellTables.html) – iwatakeshi
좀 더 자세한 내용을 포함하도록 예제를 확장했습니다 – Jason