• 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: Line Numbers in Tables
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Line Numbers in Tables (From: Gordon Apple <email@hidden>)
 >Re: Line Numbers in Tables (From: Antonio Nunes <email@hidden>)
 >Re: Line Numbers in Tables (From: mmalc crawford <email@hidden>)

  • Prev by Date: Re: NSPersistentDocument and Multiple Managed Object Models?
  • Next by Date: How to prevent NSApp from NSBeeping ?
  • Previous by thread: Re: Line Numbers in Tables
  • Next by thread: Re: Line Numbers in Tables
  • Index(es):
    • Date
    • Thread