Re: table row numbers with NSArrayController
Re: table row numbers with NSArrayController
- Subject: Re: table row numbers with NSArrayController
- From: Daryn <email@hidden>
- Date: Fri, 26 Dec 2003 03:12:26 -0600
I must have missed mmalc's response. All I'm really searching for is
an absolute row number in the table, not the object's index, so it
would seem using an index in the model wouldn't work. Or am I
misunderstanding?
Now that I have been spoiled by controllers, I really don't want to
have to add a datasource just for this simple behavior. Someone needs
to please devise a clever solution, because I came up with this
absolutely putrid solution:
@interface MyRowNumberCell : NSTextFieldCell {}
@end
@implementation MyRowNumberCell
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
NSAssert([controlView isKindOfClass:[NSTableView class]],@"gack, use
me in a tableView!");
int row = [(NSTableView*)controlView rowAtPoint:cellFrame.origin];
[self setObjectValue:[NSString stringWithFormat:@"%i",row]];
[super drawWithFrame:cellFrame inView:controlView];
}
@end
On Dec 26, 2003, at 1:27 AM, Scott Anguish wrote:
>
one potential issue that mmalc raised is that you'd typically bind the
>
table items to the arranged objects, so you'd need to do this at the
>
controller level (as you have).
>
>
if you're trying to do what iTunes does in displaying the numbers
>
beside the tunes, I think the indexes would need to be kept in the
>
data model. that way even when they're rearranged they'll be correct.
>
>
>
>
On Dec 26, 2003, at 2:22 AM, Daryn wrote:
>
>
> On Dec 24, 2003, at 1:43 PM, Scott Anguish wrote:
>
>>
>
>> On Dec 24, 2003, at 1:59 PM, Daryn wrote:
>
>>
>
>>> Is there a table binding that would allow the display of the row
>
>>> number?
>
>>>
>
>>
>
>> there isn't a binding or option for that, no.
>
>>
>
>> I can't think of a way to do that that wouldn't be pretty hacky,
>
>> aside from having the model object have a key that can return the
>
>> index of an object in the array.
>
>
>
> I thought I'd be clever and bind the row number column to a
>
> controller key of "rowNumbers" and do this:
>
>
>
> @implementation NSArrayController (MyArrayControllerAdditions)
>
> - (unsigned int)countOfRowNumbers { return [[self content] count]; }
>
> - (id)objectInRowNumbersAtIndex:(unsigned int)index { return
>
> [NSString stringWithFormat:@"%i",index]; }
>
> @end
>
>
>
> Unfortunately every cell gets the entire array of row numbers.
>
> Naturally I'd like the array controller to treat rowNumbers like
>
> arrangedObjects and use the row number as an index into the array.
>
> Is the arrangedObjects property specially hardcoded into the array
>
> controller, or is there a programatic way to set this "indexable
>
> behavior" on a property?
>
>
>
> (I know I can do row numbers easily with a datasource, but I'm just
>
> having fun experimenting with controllers)
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
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.