setting up radio buttons

  • Hi All,

    I am trying to set up a series of radio buttons. I have used matrices
    before, and they worked fine, but for some reason, I can't find any
    examples on how to get radio buttons to work.

    I declared the radio button outlet as an NSButtonCell and connected
    the GUI to the instantiated controller object. But when I try to get
    the state, the values are wrong. For three buttons, titled TAB,
    COMMA, and OTHER, I get the following logs when attempting to get the
    state for all three.

    <pressing tab and hitting a get state button>
    2007-09-19 16:21:13.386 GenericParser[1436] The cell is 1
    2007-09-19 16:21:13.386 GenericParser[1436] Cell title is Tab

    <pressing comma and hitting the get state button>
    2007-09-19 16:21:05.368 GenericParser[1436] The cell is 0
    2007-09-19 16:21:05.368 GenericParser[1436] Cell title is Tab
    (should be Comma)

    <pressing other and hitting the get state button>
    2007-09-19 16:21:09.157 GenericParser[1436] The cell is 0
    2007-09-19 16:21:09.157 GenericParser[1436] Cell title is Tab
    (should be Other)

    Obviously the titles of the second and third buttons are not
    recognized, and the state is 1 for Tab no matter what and 0 for the
    others. My code is really a guess since I can't find documentation or
    examples.

    int buttonState; // the radio button cell selected
    NSString *radButtonTitle;      // the title of the radio button
    selected

          buttonState = [fieldDelimRadioButton state];
    NSLog(@"The cell is %i\n", buttonState);
    radButtonTitle = [fieldDelimRadioButton title];
    NSLog(@"Cell title is %@\n", radButtonTitle);

    At this point, if anyone knows of a good link to info on how to get
    and set the state of the button, I'd really appreciate. I can't seem
    to find any documentation or examples. Thanks very much.

    Daniel
  • On Sep 19, 2007, at 3:29 PM, Daniel Child wrote:

    > Hi All,
    >
    > I am trying to set up a series of radio buttons. I have used
    > matrices before, and they worked fine, but for some reason, I can't
    > find any examples on how to get radio buttons to work.
    ...
    > Obviously the titles of the second and third buttons are not
    > recognized, and the state is 1 for Tab no matter what and 0 for the
    > others. My code is really a guess since I can't find documentation
    > or examples.
    >
    > int buttonState; // the radio button cell selected
    > NSString *radButtonTitle;      // the title of the radio button
    > selected
    >
    > buttonState = [fieldDelimRadioButton state];
    > NSLog(@"The cell is %i\n", buttonState);
    > radButtonTitle = [fieldDelimRadioButton title];
    > NSLog(@"Cell title is %@\n", radButtonTitle);

    [Reports the title of fieldDelimRadioButton as "Tab". Reports state as
    1 or 0, depending on whether the Tab button is selected.]

    This would be the correct behavior if fieldDelimRadioButton were the
    Tab button (or cell) in every case.

    You don't say how fieldDelimRadioButton is set. What happens if you
    set it to [yourMatrix selectedCell]?

    — F
  • on 9/19/07 2:29 PM, <wchild...> purportedly said:

    > before, and they worked fine, but for some reason, I can't find any
    > examples on how to get radio buttons to work.
    >
    > I declared the radio button outlet as an NSButtonCell and connected
    > the GUI to the instantiated controller object. But when I try to get
    > the state, the values are wrong. For three buttons, titled TAB,
    > COMMA, and OTHER, I get the following logs when attempting to get the
    > state for all three.

    When you set an outlet in this way, your outlet will only and always refer
    to the specific button you are connected to, and not the matrix "state". You
    may want to have the outlet to the nsmatrix instead.

    Best,

    Keary Suska
    Esoteritech, Inc.
    "Demystifying technology for your home or business"
  • Just connect the matrix to an action and read the cell and cell tag;

    - (IBAction)radioModeMatrixAction:(id)sender
    {
        id selectedCell = [sender selectedCell];
        if (selectedCell)
        {
            userResponse = [selectedCell tag];
        }
    }

        You can connect an outlet to the matrix to set the initial choice if
    desired:

        [radioButtons selectCellWithTag:0];    //  Or whatever tag

        I think you could also do a series of them with the same action method
    if you first check the matrix tag for each set before getting the selected
    cell.  I recently set up a sheet controller to do this.

    > I am trying to set up a series of radio buttons. I have used matrices
    > before, and they worked fine, but for some reason, I can't find any
    > examples on how to get radio buttons to work.
    >
    > I declared the radio button outlet as an NSButtonCell and connected
    > the GUI to the instantiated controller object. But when I try to get
    > the state, the values are wrong. For three buttons, titled TAB,
    > COMMA, and OTHER, I get the following logs when attempting to get the
    > state for all three.
previous month september 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Go to today