Re: Basic issues regarding Tables
Re: Basic issues regarding Tables
- Subject: Re: Basic issues regarding Tables
- From: email@hidden
- Date: Sun, 6 Feb 2005 16:55:24 -0500 (EST)
- Importance: Normal
> I have a Table with 2 columns, the first column contains
> NSTextFieldCells, the second NSButtonCells.
>
The set objectValue ... Method can be used here to edit the dictionary
contents.
- (void) tableView: (NSTableView *)tView
setObjectValue: (id)object
forTableColumn: (NSTableColumn *)aTableColumn
row: (int)rowIndex
{
if([aTableColumn isEqualTo:@"classpath"]){
[[classPathRecords objectAtIndex:rowIndex] setObject:object
forKey:@"classpath"];
}
else if([aTableColumn isEqualTo:@"active"]){
[[classPathRecords objectAtIndex:rowIndex] setObject:[[NSNumber
numberWithInt:[object state]] //I might have this part wrong
forKey:@"active"];
}
}
Any way I'm typing this at work in an email app so it's untested.
> 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.
>
In your delete row I would do a <b>reverse</b> object enumerator of the
row indexes and then a simple [classPathRecords
removeObjectAtIndex:[rowIndex intValue]];
You can get the selected rows array with [tableView selectedRows] I
think... Haven't had to work with indexes for a while and memory fails
me, but there is a selected rows method that returns an array of
NSNumbers for the indexes.
April.
> 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
>
_______________________________________________
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