• 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: Access to value in dictionary from Interface Builder?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Access to value in dictionary from Interface Builder?


  • Subject: Re: Access to value in dictionary from Interface Builder?
  • From: "Arthur C." <email@hidden>
  • Date: Tue, 06 Mar 2007 19:52:14 +0100

I have created a table view to show the values in the dictionary. Binding to the dictionary keys directly does not seem to work, so I use an array controller for this:

@interface Diagnostics : NSObject
{
NSMutableArray * diagnostics;
IBOutlet NSArrayController * array;
}
@implementation Diagnostics
- (void) awakeFromNib
{
NSMutableDictionary *diagnosticsDictionary = [[NSMutableDictionary alloc] initWithCapacity: 5];
[diagnosticsDictionary setValue: @"75" forKey: @"height"];
[diagnosticsDictionary setValue: @"9" forKey: @"width"];
[diagnosticsDictionary setValue: @"84" forKey: @"lenght"];


// I start with a dictionary containing values and keys; the keys should go to the first column of the table view, the values to the second.
NSEnumerator * myEnum = [diagnosticsDictionary keyEnumerator];
NSString *aKey;
diagnostics = [[NSMutableArray alloc] initWithCapacity: 5];
while( aKey = [myEnum nextObject] )
{
NSDictionary * localDict = [NSDictionary dictionaryWithObjectsAndKeys: [diagnosticsDictionary valueForKey: aKey], @"value", aKey, @"key1", nil];
[diagnostics addObject: localDict];
// The values and keys are added to an array of dictionaries, each of which contains one value and one key
}


[array addObject: [NSDictionary dictionaryWithObjectsAndKeys: @"color", @"key1", @"Red", @"value", nil]];
// just for testing, see below
}


Now the array controller 'array' is bound to 'diagnostics' (which is the contentArray), and to the table columns. One column is bound to 'arrangedObjects.key1' from the array controller, the other to 'arrangedObjects.value'.
The strange thing is that the program will crash when I omit the '[array addObject: ...]' line, while it will work just fine if it is included... Some other options such as filling the array controller directly won't work either. I must be doing something wrong here, but I can't see from the docs how to do this.



Any suggestions? Thanks in advance,

Arthur C.


From: "Arthur C." <email@hidden>
To: email@hidden
Subject: Access to value in dictionary from Interface Builder?
Date: Thu, 22 Feb 2007 22:20:24 +0100

Hello,

I want to use a dictionary to store some 10 or 20 values for a status window.
My question is how to access the values within Interface Builder to bind them to an interface window.
So assume I have an


 NSDictionary *diagnosticsInfo;

and I want to show

[diagnostics valueForKey: @"serialNumber"],
[diagnostics valueForKey: @"releaseVersion"] etc.

in the interface window. Do I need to use valueForKeyPath or something?


Thanks in advance,

Arthur C.

_________________________________________________________________
Hotmail en Messenger on the move http://www.msn.nl/services


_________________________________________________________________
Talk with your online friends with Messenger http://www.join.msn.com/messenger/overview


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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


  • Follow-Ups:
    • Re: Access to value in dictionary from Interface Builder?
      • From: mmalc crawford <email@hidden>
  • Prev by Date: Re: Counting the number of files in a directory
  • Next by Date: Re: Access to value in dictionary from Interface Builder?
  • Previous by thread: Fwd: MEETING: Core Image Chicago CocoaHeads / CAWUG Tuesday 3/13 -
  • Next by thread: Re: Access to value in dictionary from Interface Builder?
  • Index(es):
    • Date
    • Thread