to select a single cell in NSMatrix

  • Hi,

    I am working on an app that shows a file's preview in hex (see attached
    image of the NSMatrix).

    I wish to highlight a single cell when the user clicks on it. For that I
    zeroed in on target/action mechanism.

    But its not working for me.

    What I have done:



    In AppController.m in init():

    [matrixHex setTarget:@selector(cellClicked:)];

    [ self enableHexCells];



    In enableHexCells() I'm doing:

    -selecting cells recursively(selectCellAtRow: column:), then

    [[matrixHex selectedCell] setEnabled];



    In cellClicked() I'm doing:

    [[sender selectedCell] setHighlighted:YES]



    For target/action mechanism I have connected cellClicked in AppController as
    the target of this NSMatrix.





    What's the right way to implement this mechanism. In debugger the control
    never reaches cellClicked().



    Wishes,

    Navneet
  • Hi, Navneet,

    The problem may be that you're setting the target and action in -init;
    also, you're going to want to set the *action* to cellClicked:, rather
    than the *target*.  Try -awakeFromNib instead.  The reason that I say
    this is that your nib file will not necessarily have its objects
    loaded yet when -init is called.  Using -awakeFromNib will save you a
    great deal of trouble, I think:

    - (void)awakeFromNib {
    [matrixHex setAction:@selector(cellClicked:)];
    [self enableHexCells];
    }

    You'll want to set a target, too, I think.

    Cheers,
    Andrew

    On Jan 5, 2008, at 6:46 PM, Navneet Kumar wrote:

    > Hi,
    >
    > I am working on an app that shows a file's preview in hex (see
    > attached
    > image of the NSMatrix).
    >
    > I wish to highlight a single cell when the user clicks on it. For
    > that I
    > zeroed in on target/action mechanism.
    >
    > But its not working for me.
    >
    > What I have done:
    >
    >
    >
    > In AppController.m in init():
    >
    > [matrixHex setTarget:@selector(cellClicked:)];
    >
    > [ self enableHexCells];
    >
    >
    >
    > In enableHexCells() I'm doing:
    >
    > -selecting cells recursively(selectCellAtRow: column:), then
    >
    > [[matrixHex selectedCell] setEnabled];
    >
    >
    >
    > In cellClicked() I'm doing:
    >
    > [[sender selectedCell] setHighlighted:YES]
    >
    >
    >
    > For target/action mechanism I have connected cellClicked in
    > AppController as
    > the target of this NSMatrix.
    >
    >
    >
    >
    >
    > What's the right way to implement this mechanism. In debugger the
    > control
    > never reaches cellClicked().
    >
    >
    >
    > Wishes,
    >
    > Navneet
previous month january 2008 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 31      
Go to today