Re: Line Numbers in Tables
Re: Line Numbers in Tables
- Subject: Re: Line Numbers in Tables
- From: Antonio Nunes <email@hidden>
- Date: Thu, 30 Aug 2007 12:14:40 +0100
On 30 Aug 2007, at 02:30, Steven W Riggins wrote:
I'm not sure if follow this. How so? The listindex is just a
property of the model object, to which binding is 'legal' afaik.
Your data could be in one view sorted ascending, at which object at
1 is 1, and in a second view sorted descending, where object at 1
is n.
Yes, that's true. What I showed is actually not simple line numbers,
but the order of the objects in the array. In my app those two happen
to always be in sync, since sorting the table view sorts the master
array. But if sorting a table view doesn't sort the underlying master
array then, even if you have only one table view, this technique
won't show the result's you're after. Apologies for the mixup and
lack of clarity.
The following however will show proper line numbers:
1. Create an NSTableView subclass:
@interface ANLineNumberTableView : NSTableView {
unsigned _lineNumber;
}
- (unsigned)lineNumber;
@end
@implementation ANLineNumberTableView
- (unsigned)lineNumber
{
unsigned result = ++_lineNumber; // increment each time we are
asked, which is once per row
if (_lineNumber == [self numberOfRows]) // when at the last row we
ned to reset the line number
_lineNumber = 0;
return result;
}
@end
2. Bind the desired table view's column to its table view's
lineNumber property.
I created a little test project and it works a treat. The project
also shows how to sort numbers in strings numerically (rather then
alphabetically). To find the project take a break here: http://
web.mac.com/antonionunes/
If this latest code still is offensive do let me know. :-)
António
----------------------------------------------------
There is a world of difference between
searching for happiness and choosing
to be happy.
----------------------------------------------------
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden