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 00:21:51 +0100
On 29 Aug 2007, at 22:08, mmalc crawford wrote:
Don't do this.
It violates MVC -- it ties the implementation of the model object
to a particular interface configuration.
(What happens when a given object is displayed in more than one
table view?)
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.
I did have a typo in my answer though. Maybe that muddled things up a
bit:
The method in your controller object can be something to the extent
of:
should read:
The method in your controlled object...etc.
I.e: The object with the listIndex method is the object being tracked
by the array controller, not the array controller itself. And the
myArrayObject in
return [myArrayObject indexOfObject:self] + 1;
is a model object that is an array, although it might be an indirect
reference rather than direct as in the quoted example. In my app it
looks something akin to this:
@interface MyDocument : NSDocument
{
NSMutableArray *myArrayOfObjects; // ArrayController is bound to this.
}
----------
@interface MyObjectStoredInAnArray : NSObject // ArrayController's
Object Class Name is set to this class
{
id myDocument;
}
@implementation MyObjectToBeStoredInAnArray
- (int)listIndex // The property to be bound to in the table view column
{
return [[mydocument myArrayOfObjects] indexOfObject:self] + 1;
}
@end
Of course the model object stored in the array does need to have a
reference back to a model object that gives it access to the required
information, as in the above. So the listIndex always returns a value
that is accurate within the model, regardless of however many table
views may bind to it. If the model object doesn't have access to the
array that contains it, then all this naturally won't work.
António
----------------------------------------------------
It isn't so important to do great things,
as to do what you do with great love.
----------------------------------------------------
_______________________________________________
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