NSMatrix defeats me

Dear Lazyweb,

I just can't figure out how to bind a Cocoa NSMatrix properly.

I want to make a set of radio buttons that look like this on screen:

  • "Computer Name and Time"
  • "Text"
  • "File"
  • "URL"

I want this set of radio buttons to be associated with a preference called "textMode" and take on the string values "date", "literal", "file", or "url". That is, when the first radio button is selected, I want the "textMode" preference set to the string "date", and not to the string "Computer Name and Time". Likewise, when the window comes up, I want the first radio button to be the selected one if the "textMode" preference already has the value "date".

I'm making the radio buttons like this: <lj-cut text=" --More--(24%) ">

    NSButtonCell *proto = [[NSButtonCell alloc] init];
    [proto setButtonType:NSRadioButton];

    NSMatrix *matrix = [[NSMatrix alloc]

    NSArrayController *cvalues =
     [[NSArrayController alloc] initWithContent:nil];
    [cvalues addObject:@"date"];
    [cvalues addObject:@"literal"];
    [cvalues addObject:@"file"];
    [cvalues addObject:@"url"];
    [matrix bind:@"content"
    [matrix bind:@"selectedObject"

Now how do I set the damned labels? Based on some cargo-cult googling, I tried this, and it doesn't work:

    NSArray *cnames = [NSArray arrayWithObjects:
                       @"Computer Name and Time",
                       @"Text", @"File", @"URL", nil];
    [matrix bind:@"contentValues"

Where is this magic "arrangedObjects" string documented, and what does the second word in the string actually mean?

I also tried this, and it makes the strings show up, but also causes the radio buttons to come up with none of them selected by default, regardless of the value of the preference. Clicking on them does appear to set the preference, however, which is weird:

    NSCell *cell;
    cell = [matrix cellAtRow:0 column:0];
    [cell setTitle:@"Host Name and Time"];

    cell = [matrix cellAtRow:1 column:0];
    [cell setTitle:@"Text"];

Update: I finally just gave up, and bound it to "selectedIndex", meaning my preference takes on a numerical value instead of a string, and then I have magic knowledge about what those numbers mean in a couple places. This is annoying, but I didn't get any simple suggestions for how else to fix it. (I got a few really complicated suggestions, that may or may not have worked, but I didn't try them.)

Tags: , , ,

I have no mouth and I must photoshop

marcus132 had a fine idea for rasterbation.
(The movie's going to suck ass, though.)

<LJ-CUT text=" --More--(22%) ">

Tags: ,