• 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: "Gerriet M. Denkmann" <email@hidden>
  • Date: Tue, 21 Apr 2009 00:12:24 +0700


On 20 Apr 2009, at 23:05, Keary Suska wrote:


On Apr 19, 2009, at 1:29 AM, Gerriet M. Denkmann wrote:

I have a table with two columns, labeled "Key" and "Value" bound to myDictionaryController.key and myDictionaryController.value.

Now I want to select a row programmatically (e.g. [ myDictionaryController selectRowWIthKey: @"someKey" ]; ).
But such a method I cannot find.

There is no such facility, unfortunately. It would be nice. Why not file an enhancement request?


And trying to use the inherited "selectObjects:" does not work (nothing happens, not even an error message).

Well, -selectObjects: can't be used to change a controller's selection, so no wonder you aren't getting anywhere.
Sorry about this. It was setSelectedObjects: which I tried.


So: how can I select a row in my table?


Normally, -setSelectedObjects:, -setSelectionIndex:, or - setSelectionIndexes:. If they don't work, and you want help with that, then be specific about what precisely you tried (i.e. show code!).
Here it is:
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: defKey ] ];
// now no row is selected
return NO;
};
};

defIndex++;
};


It also helps to mention what you expect to happen, and what is actually happening differently than your expectation.

Well: there is this table bound to myDictionaryController. And I would expect that the row which contains defKey would be selected, but nothing is selected instead.


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 ] ];
};


Kind regards,

Gerriet.

_______________________________________________

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


  • Follow-Ups:
    • Re: Select Object in NSDictionaryController
      • From: Keary Suska <email@hidden>
References: 
 >Select Object in NSDictionaryController (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: Select Object in NSDictionaryController (From: Keary Suska <email@hidden>)

  • Prev by Date: Re: NSSavePanel and file formats
  • Next by Date: Compiling a XIB creates a different NIB file everytime
  • Previous by thread: Re: Select Object in NSDictionaryController
  • Next by thread: Re: Select Object in NSDictionaryController
  • Index(es):
    • Date
    • Thread