Skip to content

Instantly share code, notes, and snippets.

@KevinGutowski
Last active May 24, 2019 05:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KevinGutowski/de2240f860f42a104cccc930779da8b5 to your computer and use it in GitHub Desktop.
Save KevinGutowski/de2240f860f42a104cccc930779da8b5 to your computer and use it in GitHub Desktop.
Trying to render a tableview
//
// AppDelegate.m
// Tableview3
//
// Created by Kevin Gutowski on 5/23/19.
// Copyright © 2019 Kevin. All rights reserved.
//
#import "AppDelegate.h"
@interface AppDelegate () <NSTableViewDataSource>
@end
@implementation AppDelegate
-(NSArray *)dataArray
{
NSArray *array = [NSArray arrayWithObjects:
[NSDictionary dictionaryWithObjectsAndKeys:@"1001",@"key1",@"1002",@"key2",@"1003",@"key3",@"1004",@"key4",@"1005",@"key5",@"1006",@"key6",@"1007",@"key7", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"2001",@"key1",@"2002",@"key2",@"2003",@"key3",@"2004",@"key4",@"2005",@"key5",@"2006",@"key6",@"2007",@"key7", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"3001",@"key1",@"3002",@"key2",@"3003",@"key3",@"3004",@"key4",@"3005",@"key5",@"3006",@"key6",@"3007",@"key7", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"4001",@"key1",@"4002",@"key2",@"4003",@"key3",@"4004",@"key4",@"4005",@"key5",@"4006",@"key6",@"4007",@"key7", nil],
nil];
return array;
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
NSWindow *window = [[NSApplication sharedApplication] mainWindow];
NSScrollView* scrollView = [[NSScrollView alloc] initWithFrame:[[window contentView] bounds]];
[scrollView setBorderType:NSBezelBorder];
[scrollView setHasVerticalScroller:YES];
[scrollView setHasHorizontalScroller:YES];
[scrollView setAutohidesScrollers:NO];
NSRect clipViewBounds = [[scrollView contentView] bounds];
NSTableView* tableView = [[NSTableView alloc] initWithFrame:clipViewBounds];
NSTableColumn* firstColumn = [[NSTableColumn alloc] initWithIdentifier:@"firstColumn"];
[[firstColumn headerCell] setStringValue:@"First"];
[tableView addTableColumn:firstColumn];
NSTableColumn* secondColumn = [[NSTableColumn alloc] initWithIdentifier:@"secondColumn"];
[[secondColumn headerCell] setStringValue:@"Second"];
[tableView addTableColumn:secondColumn];
[tableView setDataSource:self];
[scrollView setDocumentView:tableView];
[[window contentView] addSubview:scrollView];
}
-(id) tableView:(NSTableView *)aTableView objectValueForTableColumn:(nullable NSTableColumn *)tableColumn row:(NSInteger)row {
NSString *aString;
aString = [[[self dataArray] objectAtIndex:row] objectForKey:tableColumn];
return aString;
}
-(NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
NSInteger recordCount = [[self dataArray] count];
return recordCount;
}
- (void)applicationWillTerminate:(NSNotification *)aNotification {
// Insert code here to tear down your application
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment