• 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: Select Object in NSDictionaryController
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Select Object in NSDictionaryController


  • Subject: Re: Select Object in NSDictionaryController
  • From: Keary Suska <email@hidden>
  • Date: Mon, 20 Apr 2009 14:28:01 -0600

On Apr 20, 2009, at 11:12 AM, Gerriet M. Denkmann wrote:

NSArray *defs = ...some array... (which is bound to content of definitionsArrayController)
NSUInteger defIndex = 0;
for( NSDictionary *aDef in defs )
{
for( NSString *defKey in aDef )
{
NSString *value = [ aDef objectForKey: defKey ];
BOOL ok = ... some test with value
if ( !ok ) // select the bad thing
{
[ definitionsArrayController setSelectionIndex: defIndex ]; // this works fine
// now the table shows "aDef" and the first row in the table is selected
[ myDictionaryController setSelectedObjects: [ NSArray arrayWithObject:

This doesn't work because the selected object(s) need to be the actual objects managed by the controller.


This code works (but seems incredibly complicated and inefficient):

NSArray *arrangedObjects = [ dictController arrangedObjects ];
id theThing = nil;
for( id something in arrangedObjects )
{
	NSString *key = [ something key ];
	if ( [ key isEqualToString: defKey ] )
	{
		theThing = something;
		break;
	};
};

if ( theThing == nil ) // error
{
NSLog(@"%s Error not found",__FUNCTION__);
}
else
{
[ dictController setSelectedObjects: [ NSArray arrayWithObject: theThing ] ];
};


This, or something similar, is probably your best bet. Also, chances are any other apparently shorter solution would really just do the same thing.

Best,

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"

_______________________________________________

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: 
 >Select Object in NSDictionaryController (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: Select Object in NSDictionaryController (From: Keary Suska <email@hidden>)
 >Re: Select Object in NSDictionaryController (From: "Gerriet M. Denkmann" <email@hidden>)

  • Prev by Date: Re: Compiling a XIB creates a different NIB file everytime
  • Next by Date: Re: NSArray merge sorting
  • Previous by thread: Re: Select Object in NSDictionaryController
  • Next by thread: Using CFStringTransform with Attributed strings or runs, maintaining the styling of the Attributes in transformed results.
  • Index(es):
    • Date
    • Thread