Re: Select Object in NSDictionaryController
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