Skip to content

Instantly share code, notes, and snippets.

@nicoclavier
Created January 11, 2010 11:18
Show Gist options
  • Save nicoclavier/274166 to your computer and use it in GitHub Desktop.
Save nicoclavier/274166 to your computer and use it in GitHub Desktop.
/*
* AppController.j
* CPTable
*
* Created by You on Janurary 11, 2010.
* Copyright 2010, Your Company All rights reserved.
*/
@import <Foundation/CPObject.j>
@implementation AppController : CPObject
{
CPTableView tableView;
}
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask],
contentView = [theWindow contentView];
var scrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(0,50,600,400)];
[contentView addSubview:scrollView];
var columnIdentifiers = [CPArray arrayWithArray:[@"Column 1",@"Column 2",@"Column 3"]];
tableView = [[CPTableView alloc] initWithFrame:[scrollView frame]];
[tableView setDelegate:self];
[tableView setDataSource:self];
var identifier, enumerator = ([columnIdentifiers objectEnumerator]);
while (identifier = [enumerator nextObject])
{
var column = [[CPTableColumn alloc] initWithIdentifier:identifier];
[[column headerView] setStringValue:identifier];
[[column headerView] sizeToFit];
// [[column setMinWidth:200];
[column setWidth:200];
[tableView addTableColumn:column];
}
[scrollView setDocumentView:tableView];
var button = [CPButton buttonWithTitle:@"Remove column 2"];
[button setTarget:self];
[button setAction:@selector(removeTableColumn:)];
[contentView addSubview:button];
[theWindow orderFront:self];
/* TEST 1 -> WORKS */
// [tableView removeTableColumn:[[tableView tableColumns] objectAtIndex:[tableView columnWithIdentifier:@"Column 1"]]];
// [tableView removeTableColumn:[[tableView tableColumns] objectAtIndex:[tableView columnWithIdentifier:@"Column 2"]]];
// [tableView removeTableColumn:[[tableView tableColumns] objectAtIndex:[tableView columnWithIdentifier:@"Column 3"]]];
/* TEST 2 -> LEAVES COLUMN 2 */
// var column, colEnumerator = [[tableView tableColumns] objectEnumerator];
// while (column = [colEnumerator nextObject])
// {
// [tableView removeTableColumn:column];
// }
/* TEST 3 -> fails see below */
// for (var index = 0; index < [[tableView tableColumns] count]; index++)
// {
// [tableView removeTableColumn:[[tableView tableColumns] objectAtIndex:index]]; // -> LEAVES COLUMN 2
// //[tableView removeTableColumn:[[tableView tableColumns] lastObject]]; // -> LEAVES COLUMN 1
// }
}
- (void)removeTableColumn:(id)sender
{
/* TEST 4 -> fails with console message : TypeError: Result of expression '_dataViewsForTableColumns[_116]' [undefined] is not an object. */
[tableView removeTableColumn:[[tableView tableColumns] objectAtIndex:[tableView columnWithIdentifier:@"Column 2"]]];
// console.log([[tableView tableColumns] objectAtIndex:[tableView columnWithIdentifier:@"Column 2"]]);
}
- (int)numberOfRowsInTableView:(CPTableView)tableView
{
return 50;
}
- (id)tableView:(CPTableView)tableView objectValueForTableColumn:(CPTableColumn)tableColumn row:(int)row
{
return @"Cappuccino Rocks";
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment