• 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: Updating text field bound to core data
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Updating text field bound to core data


  • Subject: Re: Updating text field bound to core data
  • From: Ron Lue-Sang <email@hidden>
  • Date: Fri, 15 Aug 2008 18:27:20 -0700


On Aug 15, 2008, at 5:59 PM, Andrew Zahra wrote:

Excellent! It is starting to make sense to me now. I am using an ArrayController. I did this and it works:

			NSManagedObject *task = [controller selection];
			[task setValue:fileName forKey:@"sourceFolder"];

Keep in mind that this isn't strictly true. The array/object/tree controller's have a selection property that, if you were to log/ inspect it, is just an opaque proxy object that you can use for KVC purposes. As you've seen, you can invoke setValue:forKey: on this proxy. There's also support for valueForKey: and the keyPath variants of both. There's also support for special syntax like valueFoKey:@"@count" gets you the number of selected rows. valueForKeyPath:@"@sum.weight" gets you the sum of all the selected objects' weight values. And when you invoke setValue:forKeyPath:, the change will be sent to all of the selected objects.


So in your example above, if you have more than one object selected, all of the objects will get the new "sourceFolder" value. You can declare task like

id task = [controller selection];

or as some will prefer for true technical correctness

id<NSObject *> task = [controller selection];





2008/8/16 Ron Lue-Sang <email@hidden>

On Aug 15, 2008, at 4:57 PM, Andrew Zahra wrote:

I am working on a basic core data app. I have a single entity with a name
attribute and other attributes including a file path. I have bound a table
view to the entity name and then a group of text fields to the individual
attributes to show the details. It works fine if I type stuff directly into
these field.
The problem is, I want to set the value of the file path based on a user
selection from an NSOpenPanel. I tried setting the value of the text field
with setStringValue,


Yea, that's trying to change the value from the wrong direction. Tell your friends, "don't try to change a bound value by directly manipulating the view".


but that did not end up stored by core data.

I am guessing I have to access the currently selected managed object somehow
and then update it, but none of the core data examples I have seen do
anything like this. Can someone point me in the right direction?


There's nothing coredata specific about this. You must either have an arrayController or a traditional NSTableView datasource object feeding your table view. If you're using an arrayController, use the arrayController's selection property (as opposed to selectedObjects, that way you can handle multiple selection for free). Or you implemented the tableView dataSource method for tableView:selectionDidChangeToIndexes: or whatever that method is.

Make sense?




Thanks, Andrew _______________________________________________

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




-- Zahra Consulting Services www.zcs.com.au

_______________________________________________

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: 
 >Updating text field bound to core data (From: "Andrew Zahra" <email@hidden>)
 >Re: Updating text field bound to core data (From: Ron Lue-Sang <email@hidden>)
 >Re: Updating text field bound to core data (From: "Andrew Zahra" <email@hidden>)

  • Prev by Date: Re: Window 'close' action fails
  • Next by Date: Re: Window 'close' action fails
  • Previous by thread: Re: Updating text field bound to core data
  • Next by thread: Using Flex/Lex in a Cocoa project
  • Index(es):
    • Date
    • Thread