Basic issues regarding Tables
Basic issues regarding Tables
- Subject: Basic issues regarding Tables
- From: Philipp Ringli <email@hidden>
- Date: Sun, 6 Feb 2005 21:14:25 +0100
I have a Table with 2 columns, the first column contains
NSTextFieldCells, the second NSButtonCells.
Right now, I am having the following issues (@ runtime):
1. When I edit a row, it doesn't keep the values.
2. When I want to delete a row, all rows are removed.
Cheers,
Phil
Controller.m
------------------------------------------------------------------------
------------------
-(NSDictionary *)createRecord
{
NSMutableDictionary *record = [NSMutableDictionary dictionary];
[record setObject:@"Please enter Classpath..." forKey:@"classpath"];
[record setObject:[NSNumber numberWithBool:YES] forKey:@"active"];
return record;
}
- (IBAction) addRecord:(id) sender
{
[classPathRecords addObject:[self createRecord]];
[classPathTable reloadData];
}
- (int)numberOfRowsInTableView:(NSTableView *)aTableView
{
return [classPathRecords count];
}
- (IBAction) deleteRecords:(id) sender
{
NSEnumerator *enumerator = [classPathTable selectedRowEnumerator];
NSNumber *index;
NSMutableArray *tempArray = [NSMutableArray array];
id tempObject;
while ( (index = [enumerator nextObject]) ) {
tempObject = [classPathRecords objectAtIndex:[index intValue]]; // No
modification, no problem
[tempArray addObject:tempObject]; // keep track of the record to
delete in tempArray
}
[classPathRecords removeObjectsInArray:tempArray]; // we're golden
[classPathTable reloadData];
}
-(id)tableView:(NSTableView *)aTableView
objectValueForTableColumn:(NSTableColumn *)aTableColumn
row:(int)rowIndex
{
id theRecord, theValue;
theRecord = [classPathRecords objectAtIndex:rowIndex];
theValue = [theRecord objectForKey:[aTableColumn identifier]];
return theValue;
}
- (void) tableView: (NSTableView *)tView
setObjectValue: (id)object
forTableColumn: (NSTableColumn *)aTableColumn
row: (int)rowIndex
{
// No idea, if this is needed...
}
-(void)awakeFromNib
{
classPathRecords = [[NSMutableArray alloc] init];
}
------------------------------------------------------------------------
----------------------------------------
Controller.h
------------------------------------------------------------------------
----------------------------------------
@interface Controller : NSObject <TaskWrapperController>
{
IBOutlet id asFilePathTf;
IBOutlet id swfFilePathTf;
//classPath manager
NSMutableArray *classPathRecords; // an array holding dictionary
Objects
IBOutlet id classPathTable; // Ref to View: NSTableView (NIB)
}
- (IBAction)chooseAsFile:(id)sender;
- (IBAction)chooseSwfFile:(id)sender;
- (IBAction)addRecord:(id)sender;
- (IBAction)saveRecords:(id)sender;
- (IBAction)deleteRecords:(id)sender;
- (IBAction)displayReleaseNotes:(id)sender; // powers our addition to
the help menu
@end
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden