• 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: More Newbie Trouble with Basic Bindings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: More Newbie Trouble with Basic Bindings


  • Subject: Re: More Newbie Trouble with Basic Bindings
  • From: Scott Stevenson <email@hidden>
  • Date: Fri, 1 Apr 2005 09:01:03 -0800


On Apr 1, 2005, at 7:56 AM, Kane Dijkman wrote:

Is that how it is supposed to be done?

You have a few options. Let's say you have an array called "songs", with a MyController class that owns the array.


The easiest way to make sure the array changes are observed is this (in MyController.m):

- (void) addSong: (Song *)song
{
	NSMutableArray * array = [self mutableArrayValueForKey: @"songs"];
	[array addObject: song];
}

The -mutableArrayValueForKey message returns a special object which updates bound views.

Another option is to use Indexed Accessors, which *might* perform a bit better with a lot of instances:
<http://developer.apple.com/documentation/Cocoa/Conceptual/ KeyValueCoding/Concepts/AccessorConventions.html#//apple_ref/doc/uid/ 20002174/BAJEDEFB>


Kevin Callahan's Accessorizor app can generate them for you:
<http://www.kevincallahan.org/software/accessorizer.html>



Currently I have an object with two values (one for each column) that has an instance for each line in the NSTableView. Each of those instances is stored in an array that the ArrayController is bound too. And the array is created in my controller class.

So I am not sure how I would use willChangeValueForKey or what the "key" is.

For your purposes, the key is just the name of the array.


Do I need to change the data model?
Do I need a new class that has the array in it?

Nope.


Bindings seem to be a great way to do stuff, but the limited amount of documentation and examples is making it hard for this beginner to get ones head around it all.

Doesn't directly address your question, but this might help you understand bindings more:
http://cocoadevcentral.com/articles/000080.php



Hope that helps,

   - Scott


-- http://treehouseideas.com/ http://theocacao.com/ [blog]

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Re: More Newbie Trouble with Basic Bindings (From: Kane Dijkman <email@hidden>)

  • Prev by Date: Re: AppleEvents
  • Next by Date: Re: More Newbie Trouble with Basic Bindings
  • Previous by thread: Re: More Newbie Trouble with Basic Bindings
  • Next by thread: Re: More Newbie Trouble with Basic Bindings
  • Index(es):
    • Date
    • Thread