Re: Newbie: NSTable Autosave name not conforming to NSCoding
Re: Newbie: NSTable Autosave name not conforming to NSCoding
- Subject: Re: Newbie: NSTable Autosave name not conforming to NSCoding
- From: Jeremy Dronfield <email@hidden>
- Date: Tue, 1 Oct 2002 14:45:56 +0100
On Tuesday, October 1, 2002, at 08:34 am, Jay Prince wrote:
This doesn't seem to be in the archives. I have an application with a
couple NSTables, and I'm using a single controller.
[...]
I can use the tag if that's the officially sanctioned way-- I just tend
to be more likely to put the wrong tag value in, and rarely put the
wrong name in for an autosave name.
I don't know whether there's an officially sanctioned approach, tho' I
believe the consensus is that using a single controller is acceptable if
the two tables are related in some way (functionally or conceptually
interdependent), but to use separate data sources otherwise.
Anyway, using the tables' tags is the method I use in this situation.
With two NSMutableArrays for my data - one for each table - and the
tables tagged as 0 and 1, I proceed like so:
- (int)numberOfRowsInTableView:(NSTableView *)aTableView
{
return [aTableView tag] == 0 ? [firstArray count] : [secondArray
count];
}
- (id)tableView:(NSTableView *)aTableView
objectValueForTableColumn:(NSTableColumn *)aTableColumn row:
(int)rowIndex
{
id theRecord, theValue;
if ([aTableView tag] == 0) {
NSParameterAssert(rowIndex >= 0 && rowIndex < [firstArray
count]);
theRecord = [firstArray objectAtIndex:rowIndex];
theValue = [theRecord objectForKey:[aTableColumn identifier]];
} else {
NSParameterAssert(rowIndex >= 0 && rowIndex < [secondArray
count]);
theRecord = [secondArray objectAtIndex:rowIndex];
theValue = [theRecord objectForKey:[aTableColumn identifier]];
}
return theValue;
}
Then, when you call [myFirstTable reloadData] and [mySecondTable
reloadData] the right data will load into the right table.
BTW, I haven't checked, but I seem to recall that the
-tableViewSelectionDidChange: notification will only work for one of the
tables. I may be wrong about that, though.
Hope this helps.
-Jeremy
========================================
email@hidden // email@hidden
The Alchemy Pages:
- fractious fiction at
http://freespace.virgin.net/jeremy.dronfield
========================================
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.