Created
January 26, 2011 00:13
-
-
Save MCF/795979 to your computer and use it in GitHub Desktop.
AppController.j for example of tableview editing bug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* AppController.j | |
* TableViewBug | |
* | |
* Created by You on January 25, 2011. | |
* Copyright 2011, Your Company All rights reserved. | |
*/ | |
@import <Foundation/CPObject.j> | |
@import <AppKit/CPTableView.j> | |
@implementation AppController : CPObject | |
{ | |
CPArray tableContents; | |
} | |
- (void)applicationDidFinishLaunching:(CPNotification)aNotification | |
{ | |
var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask], | |
contentView = [theWindow contentView]; | |
// Make CPLog output look a little nicer, and have it produce debug output | |
// even when index.html is being used. | |
function plainFormatter(aString, aLevel, aTitle) | |
{ | |
return aString; | |
} | |
CPLogRegisterRange(CPLogDefault, "debug", "debug", plainFormatter); | |
tableContents = ["First Item", "Second Item", "Third Item"]; | |
myTableView = [[CPTableView alloc] initWithFrame:[contentView bounds]]; | |
[myTableView setAllowsMultipleSelection:NO]; | |
[myTableView setAllowsEmptySelection:NO]; | |
[myTableView setColumnAutoresizingStyle:CPTableViewLastColumnOnlyAutoresizingStyle]; | |
[myTableView setSelectionHighlightStyle:CPTableViewSelectionHighlightStyleSourceList]; | |
[myTableView setUsesAlternatingRowBackgroundColors:YES]; | |
[myTableView setHeaderView:nil]; | |
[myTableView setDataSource:self]; | |
[myTableView setDelegate:self]; | |
var column = [[CPTableColumn alloc] initWithIdentifier:@"TestItems"]; | |
[column setWidth:CGRectGetWidth([contentView frame])]; | |
[column setEditable:YES]; | |
[myTableView addTableColumn:column]; | |
[contentView addSubview:myTableView]; | |
[theWindow orderFront:self]; | |
} | |
- (int)numberOfRowsInTableView:(CPTableView)tableView | |
{ | |
return [tableContents count]; | |
} | |
- (id)tableView:(CPTableView)tableView objectValueForTableColumn:(CPTableColumn)tableColumn row:(int)row | |
{ | |
var rowValue = [tableContents objectAtIndex:row]; | |
CPLog.debug("From objectValueForTableColumn, row: " + row + " value: \"" + rowValue + "\""); | |
return rowValue; | |
} | |
- (BOOL)tableView:(CPTableView)aTableView shouldEditTableColumn:(CPTableColumn)tableColumn row:(int)row | |
{ | |
return YES; | |
} | |
- (void)tableView:(CPTableView)tableView setObjectValue:(id)aValue forTableColumn:(CPTableColumn)tableColumn row:(int)row | |
{ | |
tableContents[row] = aValue; | |
CPLog.debug(" - Reloading data"); | |
[tableView reloadData]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment