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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to