1
我拼湊了以下代碼來填充表視圖並希望能夠從數組中填充它。 任何人都可以告訴我一些如何?Obj-c OS X:在表視圖中填充項目
- (void)applicationWillTerminate:(NSNotification *)aNotification {
// Insert code here to tear down your application
NSLog(@"a"); }
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSRect scrollFrame = NSMakeRect(20, 74, 155, 296);
NSScrollView* scrollView = [[NSScrollView alloc] initWithFrame:scrollFrame];
[scrollView setBorderType:NSBezelBorder];
NSRect clipViewBounds = [[scrollView contentView] bounds];
NSTableView* tableView = [[NSTableView alloc] initWithFrame:clipViewBounds];
NSTableColumn* firstColumn = [[NSTableColumn alloc] initWithIdentifier:@""];
[tableView addTableColumn:firstColumn];
[tableView setHeaderView:nil];
[tableView setDataSource:self];
[tableView setRowHeight:40.0];
[scrollView setDocumentView:tableView];
[[[self window] contentView] addSubview:scrollView];
}
- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
{
return 5;
}
- (id) tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
{
NSString* cellValue = [NSString stringWithFormat:@"%@ %ld", [aTableColumn identifier], (long)rowIndex];
return cellValue;
}
你需要添加功能的tableView或只是文本,以細胞的所有單元靜態細胞?並且你在使用筆尖(storyboard)還是xib? – YuviGr 2015-02-06 22:05:05
使用XIB文件。我需要添加的唯一功能是設置每個單元格的背景顏色的能力。 – asimpleman 2015-02-06 22:15:23
故事板允許您完全配置靜態表格視圖及其單元格。 – jlehr 2015-02-06 23:41:33