Re: mutableArrayForKeyValue Question (ignore other email)
Re: mutableArrayForKeyValue Question (ignore other email)
- Subject: Re: mutableArrayForKeyValue Question (ignore other email)
- From: Stuart Malin <email@hidden>
- Date: Sun, 29 Jun 2008 10:44:42 -0700
On Jun 29, 2008, at 7:05 AM, Scot t Anguish wrote:
From: Scott Anguish <email@hidden>
Subject: Re: mutableArrayForKeyValue Question (ignore other email)
To: "Alex Wait" <email@hidden>
Cc: cocoa-dev <email@hidden>
Message-ID: <email@hidden>
Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes
I think there is still some clarification necessary.
what exactly are you trying to accomplish, rather than how you are
trying to do it?
would I be correct to guess that you want to create a new Person
object and add it to the array?
if so you need to create the object and add it to the array
id newObjectToAdd = [theArrayController newObject];
[theArrayController addObject:newObjectToAdd];
or you can programmatically create the Person object, and add it
directly to the datamodel using, say
Person *aPerson=[[[Person alloc] init] autorelease];
and then add that to the data model using the mutableArrayforKeyValue:
As I am playing around with the very same concepts now, I tried these
two approaches in my code, and get (slightly) different results.
When using the controller to add the Person object, the added object
is NOT initialized. My Person class's -init method sets initial
values for its ivar properties. When I create an explicit instance of
aPerson, and add that to the model, the values are shown in the view
(s). However, when I use the controller to add a new object, the
ivars are not initialized.
Am I doing something wrong? Or is this is known artifact of using the
controller as an intermediary to add an new instance?
~~~
Separately, there's another way to add an explicitly created Person
to the data model -- using the index accessors, such as:
[mutableArrayModel insertObject:aPerson in<Key>AtIndex:
[mutableArrayModel countOf<Key>]];
Actually, in my case, I made an instance method in the model class
that adds a new person: -(void) add<Key>:(Person*)aPerson that
invokes the above referenced index accessors on self to add the new
person to the <Key> property.
_______________________________________________
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