Created
April 17, 2011 21:12
-
-
Save dbrajkovic/924474 to your computer and use it in GitHub Desktop.
Example of Editable CPTableView
This file contains 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
@implementation ManageWatchListsController : CPObject | |
{ | |
@outlet CPTableView watchListTableView; | |
@outlet CPButtonBar buttonBar; | |
CPArray watchLists; | |
var selectedWatchList; | |
} | |
-(void)init | |
{ | |
self = [super init]; | |
return self; | |
} | |
-(void)awakeFromCib{ | |
[self setWatchlists:[CPArray arrayWithObjects:@"Default", @"Another one", @"Special One"]]; | |
var addButton = [CPButtonBar plusButton]; | |
[addButton setAction:@selector(add:)]; | |
[addButton setTarget:self]; | |
[addButton setEnabled:YES]; | |
var minusButton = [CPButtonBar minusButton]; | |
[minusButton setAction:@selector(remove:)]; | |
[minusButton setTarget:self]; | |
[minusButton setEnabled:YES]; | |
[buttonBar setButtons:[addButton, minusButton]]; | |
[buttonBar setHasResizeControl:NO]; | |
} | |
-(void)add:(id)sender | |
{ | |
newRequest = [[RESTRequest alloc] init]; | |
} | |
-(void)remove:(id)sender | |
{ | |
var watchList = [watchLists objectAtIndex:[watchListTableView selectedRow]]; | |
[watchLists removeObject:watchList]; | |
[watchListTableView reloadData]; | |
} | |
-(void)setWatchLists:(CPArray)anArray | |
{ | |
watchLists = anArray; | |
[watchListTableView reloadData]; | |
} | |
- (id)tableView:(CPTableView)aTableView objectValueForTableColumn:(int)aColumn row:(int)row | |
{ | |
var value = [[watchLists objectAtIndex:row] valueForKeyPath:"watch_list.name"]; | |
return value; | |
} | |
- (int)numberOfRowsInTableView:(CPTableView)aTableView | |
{ | |
return [watchLists count]; | |
} | |
- (id)tableView:(CPTableView)aTableView | |
setObjectValue:(id)anObject | |
forTableColumn:(CPTableColumn)tableColumn | |
row:(int)row | |
{ | |
var watchList = [watchLists objectAtIndex:row]; | |
[watchList setValue:anObject forKeyPath:"watch_list.name"]; | |
var request = [[RESTRequest alloc] init]; | |
} | |
- (void)tableViewSelectionDidChange:(CPNotification )notification | |
{ | |
var tableView = [notification object]; | |
var aRow = [tableView selectedRow] | |
if (aRow > -1) { | |
selectedWatchList = [watchLists objectAtIndex:aRow]; | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment