• 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: NSDictionary, NSTableView and binding
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSDictionary, NSTableView and binding


  • Subject: Re: NSDictionary, NSTableView and binding
  • From: j o a r <email@hidden>
  • Date: Tue, 21 Mar 2006 00:19:43 +0100


On 20 mar 2006, at 23.36, Jeff Andrews wrote:

I'm sorta lost. I have a NSTableView that binds to a NSDictionary using
a NSArrayController. I believe I have the right binding names etc. via Interface Builder.
Both key and values in the Dictionary are strings.

Note that a table view is designed to display a flat list (array) of items, while a dictionary is a tree structure. Your data would probably fit better in a table view if it looked like this:


<plist version"1.0">
    <key>People</key>
    <array>
         <dict>
               <key>name</key><string>John</string>
               <key>age</key><string>29</string>
               <key>height</key><string>5 Foot 10 inches</string>
        </dict>
         <dict>
               <key>name</key><string>Mary</string>
               <key>age</key><string>27</string>
               <key>height</key><string>5 Foot 3 inches</string>
        </dict>
    </array>
</plist>

I want auto populate the table view with the NSDictionary from People.
What do I need to do to this?

You're not populating the table view, you're populating the array controller. The array controller will in turn feed the table view automatically via the bindings. If the table view and the array controller is set up already, you should be able to just use "setContentArray:" or similar to populate the array controller with the data from the file.


Also note that this code is conceptually wrong, bindings or no bindings:

	NSEnumeration* enumerator = [people objectEnumerator];
	NSDictionary* person = nil;
	while ( ( person = (NSDictionary*) [enumerator nextObject] ) )
		[tableView ?: person];

You never set data in a table view. The table view is just a view of the things found in the "table view data source". The table view fetches data for display from it's data source, traditionally via the NSTableDataSource protocol, now perhaps more often via an NSArrayController.



j o a r


Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
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: 
 >NSDictionary, NSTableView and binding (From: Jeff Andrews <email@hidden>)

  • Prev by Date: Re: CGBitmapContextCreate hates me
  • Next by Date: Re: trackingRect can't be removed?
  • Previous by thread: NSDictionary, NSTableView and binding
  • Next by thread: NSTask and root permission
  • Index(es):
    • Date
    • Thread