Checkbox in NSOutlineView

Discussion in 'Mac Programming' started by mahaboob, Sep 9, 2008.

  1. macrumors member

    Joined:
    Jul 10, 2008
    #1
    Hi all,
    I need to display a disclosure triangle, a checkbox and a textfield in the same column. I want to change the image when clicking on it and also preserve all other image states. ie, I want to perform checking and unchecking actions like those in the ordinary checkboxes.So I gone through DragNDropOutlineView exmaple provided with xcode and I copied the ImageAndTextCell class. Then I used two images checkbox_click.gif and checkbox_none.gif. My idea is to set a Flag (an instance variale) for the selected cell in the selectionDidChange: method and depending on the flag value set the appropriate image in willDisplayCell: method. In selectionDidChange: method I did like

    id cell = [[[OutlineView tableColumns] objectAtIndex:0] dataCellForRow:[OutlineView selectedRow]];
    id Name = [[cell image]name];
    if([Name isEqualToString:mad:"checkbox_none"])
    checked = YES;
    else
    checked = NO;

    And in willDisplayCell: method I did like:

    id cell = [[[OutlineView tableColumns] objectAtIndex:0] dataCellForRow:[OutlineView selectedRow]];
    id Name = [[cell image]name];
    if ([[tableColumn identifier] isEqualToString:mad:"firstColumn"])
    {
    if ([OutlineView itemAtRow:[OutlineView selectedRow]] == item)
    {
    if(checked)
    [(ImageAndTextCell *)cell setImage:[NSImage imageNamed:mad:"checkbox_click.gif"]];
    else
    [(ImageAndTextCell *)cell setImage:[NSImage imageNamed:mad:"checkbox_none.gif"]];
    }
    else
    {
    if([Name isEqualToString:mad:"checkbox_click"])
    [(ImageAndTextCell *)cell setImage:[NSImage imageNamed:mad:"checkbox_click.gif"]];
    else
    [(ImageAndTextCell *)cell setImage:[NSImage imageNamed:mad:"checkbox_none.gif"]];
    }
    }
    It is not working accurately. When I selecting one node then it will not change he image and if I selected another, both nodes images are changed. Where I got wrong ? How can I solve this ?

    Thanks in advance
     

Share This Page