Skip to content

Instantly share code, notes, and snippets.

@OneSadCookie
Created June 9, 2011 00:37
Show Gist options
  • Save OneSadCookie/1015790 to your computer and use it in GitHub Desktop.
Save OneSadCookie/1015790 to your computer and use it in GitHub Desktop.
Uglyfugly table view code
// TODO use bindings for this, once I figure out the data model...
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
{
return [[[self document] attributes] count];
}
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
assert(tableView == attributeTable);
OBAttribute *attribute = [[[self document] attributes] objectAtIndex:row];
if ([[tableColumn identifier] isEqualToString:@"attribute"])
{
return [attribute description];
}
else if ([[tableColumn identifier] isEqualToString:@"binding"])
{
NSString *identifier = [[[self document] attributeBindings] objectForKey:[attribute name]];
return [NSNumber numberWithUnsignedInt:[[tableColumn dataCell] indexOfItemWithTitle:identifier]];
}
else
{
abort();
}
}
- (void)tableView:(NSTableView *)tableView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
assert(tableView == attributeTable);
NSString *attributeName = [[[[self document] attributes] objectAtIndex:row] name];
assert([[tableColumn identifier] isEqualToString:@"binding"]);
assert([object isKindOfClass:[NSNumber class]]);
NSString *title = [[tableColumn dataCell] itemTitleAtIndex:[object unsignedIntValue]];
[[[self document] attributeBindings] setObject:title forKey:attributeName];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment