我想用自定義的NSTableCellViews創建一個NSTableview。自定義NSTableView與自定義NSTableCellView?
這是我現在所擁有的:
- 的細胞(圖筆尖)nib文件名爲CustomCell.xib
- 我的電池的自定義類稱爲CustomCell
- 並且我的代碼AppDelegate.m:
H趁着我創造我的表視圖編程:
NSScrollView *tableContainer = [[NSScrollView alloc]initWithFrame:NSMakeRect(self.window.frame.size.width-TABLEWIDTH, 0, TABLEWIDTH, self.window.frame.size.height)];
NSTableView *tableView = [[NSTableView alloc] initWithFrame:NSMakeRect(self.window.frame.size.width-TABLEWIDTH, 0, TABLEWIDTH, self.window.frame.size.height)];
NSTableColumn *firstColumn = [[[NSTableColumn alloc] initWithIdentifier:@"firstColumn"] autorelease];
[[firstColumn headerCell] setStringValue:@"First Column"];
[tableView addTableColumn:firstColumn];
tableView.dataSource = self;
tableView.delegate = self;
[tableContainer setDocumentView:tableView];
tableContainer.autoresizingMask = NSViewHeightSizable | NSViewMinXMargin;
[self.window.contentView addSubview: tableContainer];
這裏是委託方法,我希望把我的自定義單元代碼:
- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
// In IB the tableColumn has the identifier set to the same string as the keys in our dictionary
NSString *identifier = [tableColumn identifier];
if ([identifier isEqualToString:@"myCell"]) {
// We pass us as the owner so we can setup target/actions into this main controller object
CustomCell *cellView = [tableView makeViewWithIdentifier:identifier owner:self];
// Then setup properties on the cellView based on the column
cellView.textField.stringValue = @"Name";
return cellView;
}
return nil;
}
在筆尖文件爲我的自定義單元格我有掛鉤用我的自定義類叫做CustomCell,其中的子類NSTableCellView。至今我還沒有采取其他措施。所以我的CustomCell.m只是默認的初始化代碼。我沒有碰它。而且我沒有在我的nib文件中做任何其他事情,所以我沒有更改文件的所有者或其他任何東西,因爲我不知道該怎麼做。 任何人都可以幫忙嗎?我查看了Apple文檔中的示例文件,但經過幾天的研究,我還沒有找到任何解決方案。如果你能幫助我,我將不勝感激。
你能澄清是什麼問題嗎?我已閱讀你的文章幾次,我無法辨別你有什麼問題。 – FluffulousChimp
我有一個NSTableView,我想要自定義外觀的單元格。所以我建立了一個nib視圖文件,我只有這個NSTableCellView單元。現在,我想以編程方式讓我的NSTableView顯示nib文件中的特定單元格。但是上面的代碼並沒有改變我的表中的任何內容。說得通 ? –
你解決了這個問題嗎?我偶然發現了同樣的問題... – Gossamer