• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Basic issues regarding Tables
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Basic issues regarding Tables


  • Subject: Re: Basic issues regarding Tables
  • From: Philipp Ringli <email@hidden>
  • Date: Mon, 7 Feb 2005 00:07:06 +0100

I think, I got it:

this is for saving the table when it is edited:

- (void) tableView: (NSTableView *)tView
setObjectValue: (id)object
forTableColumn: (NSTableColumn *)aTableColumn
row: (int)rowIndex
{
id theRecord;
NSParameterAssert(rowIndex >= 0 && rowIndex < [classPathRecords count]);
theRecord = [classPathRecords objectAtIndex:rowIndex];
[theRecord setObject:object forKey:[aTableColumn identifier]];
return;
}


and this solves the problem of deleting all rows with identical data:

- (IBAction) deleteRecords:(id)sender
{	int status;
	NSNumber *index;
	NSArray *array = [[classPathTable selectedRowEnumerator] allObjects];
	NSEnumerator *enumerator = [array reverseObjectEnumerator];

	if ([array count] <= 0)
		return;
	while (index = [enumerator nextObject]) {
		[classPathRecords removeObjectAtIndex:[index intValue]];
		[classPathTable deselectRow:[index intValue]];
	}
	[classPathTable reloadData];
}

Thanks April!

Cheers,
Phil


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:
email@hidden


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
References: 
 >Basic issues regarding Tables (From: Philipp Ringli <email@hidden>)
 >Re: Basic issues regarding Tables (From: email@hidden)

  • Prev by Date: Re: NSSearchField crash
  • Next by Date: replaceTextStorage (second text view) and undo difficulties
  • Previous by thread: Re: Basic issues regarding Tables
  • Next by thread: Re: Basic issues regarding Tables
  • Index(es):
    • Date
    • Thread