two table view selection problem

  • Hi,
    I have two NSTableView in my app (tableView1 and tableView2).
    If I select a row in tableView1 and then if I select a row in
    tableView2, I want the row in tableView1 to be deselected.
    For this I'm using [tableView1 deselectAll: nil], but it leads to
    calling the delegate method again and leads to deselection of the
    selected row in tableView2 also.
    So this way both table view's stands deselected.

    Is there a noble way to do it?
    Listing:

    - (void)tableViewSelectionDidChange:(NSNotification *)notification
    {
    if ([[notification object] isEqual: tableView1] == YES)
    {
      [tableView2 deselectAll:nil];
      // add code here
    }

    if ([[notification object] isEqual: tableView2] == YES)
    {
      [tableView1 deselectAll:nil];
      // add code here
    }
    }

    Wishes,
    Nick
  • On Mar 4, 2008, at 3:35 PM, Nick Rogers wrote:

    > Hi,
    > I have two NSTableView in my app (tableView1 and tableView2).
    > If I select a row in tableView1 and then if I select a row in
    > tableView2, I want the row in tableView1 to be deselected.
    > For this I'm using [tableView1 deselectAll: nil], but it leads to
    > calling the delegate method again and leads to deselection of the
    > selected row in tableView2 also.
    > So this way both table view's stands deselected.
    >
    > Is there a noble way to do it?

    I'm not sure it's noble since my blood is red but:

    > Listing:
    >
    > - (void)tableViewSelectionDidChange:(NSNotification *)notification
    > {
    > if ([[notification object] isEqual: tableView1] == YES)
    > {
    >

      if ([tableView1 numberOfSelectedRows]>0)
      {
    > [tableView2 deselectAll:nil];
    >
    > // add code here
      }

    > }
    >
    > if ([[notification object] isEqual: tableView2] == YES)
    > {
    >
      if ([tableView2 numberOfSelectedRows]>0)
      {
    > [tableView1 deselectAll:nil];
    > // add code here
      }
    > }
    > }
  • Try changing the -isEqual: calls to == instead, e.g.:

    if ([notification object] == tableView1)

    I suspect -isEqual: is always returning YES.

    --Andy

    On Mar 4, 2008, at 9:35 AM, Nick Rogers wrote:

    > Hi,
    > I have two NSTableView in my app (tableView1 and tableView2).
    > If I select a row in tableView1 and then if I select a row in
    > tableView2, I want the row in tableView1 to be deselected.
    > For this I'm using [tableView1 deselectAll: nil], but it leads to
    > calling the delegate method again and leads to deselection of the
    > selected row in tableView2 also.
    > So this way both table view's stands deselected.
    >
    > Is there a noble way to do it?
    > Listing:
    >
    > - (void)tableViewSelectionDidChange:(NSNotification *)notification
    > {
    > if ([[notification object] isEqual: tableView1] == YES)
    > {
    > [tableView2 deselectAll:nil];
    > // add code here
    > }
    >
    > if ([[notification object] isEqual: tableView2] == YES)
    > {
    > [tableView1 deselectAll:nil];
    > // add code here
    > }
    > }
    >
    > Wishes,
    > Nick
  • On Mar 4, 2008, at 6:49 AM, Stéphane wrote:
    >
    > On Mar 4, 2008, at 3:35 PM, Nick Rogers wrote:
    >
    >> Hi,
    >> I have two NSTableView in my app (tableView1 and tableView2).
    >> If I select a row in tableView1 and then if I select a row in
    >> tableView2, I want the row in tableView1 to be deselected.
    >> For this I'm using [tableView1 deselectAll: nil], but it leads to
    >> calling the delegate method again and leads to deselection of the
    >> selected row in tableView2 also.
    >> So this way both table view's stands deselected.
    >>
    >> Is there a noble way to do it?
    >
    > I'm not sure it's noble since my blood is red but:
    >
    >> Listing:
    >>
    >> - (void)tableViewSelectionDidChange:(NSNotification *)notification
    >> {
    >> if ([[notification object] isEqual: tableView1] == YES)
    >> {
    >>
    >
    > if ([tableView1 numberOfSelectedRows]>0)
    > {
    >> [tableView2 deselectAll:nil];

    This will probably have the same problem; it will just stop after
    doing the callback twice.

    Let me clarify what is happening. Public "user" action entry points,
    such as deselectAll: and selectAll:, need to inform the delegate that
    the selection changed. If you use -[table selectRowIndexes:[NSIndexSet
    indexSet] byExtendingSelection:NO] then you will avoid the
    notification/delegate being notified, since it is assumed you *know*
    what you are doing as the programmer.

    -corbin
  • On Mar 4, 2008, at 8:09 AM, Andy Lee wrote:
    > Try changing the -isEqual: calls to == instead, e.g.:
    >
    > if ([notification object] == tableView1)
    >
    > I suspect -isEqual: is always returning YES.

    No, this is not the problem. Using == is okay (and faster), since
    NSView's are always unique.

    -corbin
  • On 4 mars 08, at 17:14, Corbin Dunn wrote:

    >
    > On Mar 4, 2008, at 6:49 AM, Stéphane wrote:
    >>
    >> On Mar 4, 2008, at 3:35 PM, Nick Rogers wrote:
    >>
    >>> Hi,
    >>> I have two NSTableView in my app (tableView1 and tableView2).
    >>> If I select a row in tableView1 and then if I select a row in
    >>> tableView2, I want the row in tableView1 to be deselected.
    >>> For this I'm using [tableView1 deselectAll: nil], but it leads to
    >>> calling the delegate method again and leads to deselection of the
    >>> selected row in tableView2 also.
    >>> So this way both table view's stands deselected.
    >>>
    >>> Is there a noble way to do it?
    >>
    >> I'm not sure it's noble since my blood is red but:
    >>
    >>> Listing:
    >>>
    >>> - (void)tableViewSelectionDidChange:(NSNotification *)notification
    >>> {
    >>> if ([[notification object] isEqual: tableView1] == YES)
    >>> {
    >>>
    >>
    >> if ([tableView1 numberOfSelectedRows]>0)
    >> {
    >>> [tableView2 deselectAll:nil];
    >
    > This will probably have the same problem; it will just stop after
    > doing the callback twice.

    Hmm, it works fine on Panther as far as I can tell. Would the
    notification mechanism have changed regarding this in later OS
    versions?
  • On Mar 4, 2008, at 8:28 AM, Stephane Sudre wrote:
    >
    > On 4 mars 08, at 17:14, Corbin Dunn wrote:
    >
    >>
    >> On Mar 4, 2008, at 6:49 AM, Stéphane wrote:
    >>>
    >>> On Mar 4, 2008, at 3:35 PM, Nick Rogers wrote:
    >>>
    >>>> Hi,
    >>>> I have two NSTableView in my app (tableView1 and tableView2).
    >>>> If I select a row in tableView1 and then if I select a row in
    >>>> tableView2, I want the row in tableView1 to be deselected.
    >>>> For this I'm using [tableView1 deselectAll: nil], but it leads to
    >>>> calling the delegate method again and leads to deselection of the
    >>>> selected row in tableView2 also.
    >>>> So this way both table view's stands deselected.
    >>>>
    >>>> Is there a noble way to do it?
    >>>
    >>> I'm not sure it's noble since my blood is red but:
    >>>
    >>>> Listing:
    >>>>
    >>>> - (void)tableViewSelectionDidChange:(NSNotification *)notification
    >>>> {
    >>>> if ([[notification object] isEqual: tableView1] == YES)
    >>>> {
    >>>>
    >>>
    >>> if ([tableView1 numberOfSelectedRows]>0)
    >>> {
    >>>> [tableView2 deselectAll:nil];
    >>
    >> This will probably have the same problem; it will just stop after
    >> doing the callback twice.
    >
    > Hmm, it works fine on Panther as far as I can tell. Would the
    > notification mechanism have changed regarding this in later OS
    > versions?

    I'm sure you will see the notification come through twice (once for
    each table). It just stops the recursion with the rows > 0 check. It
    works, but it is not the preferred solution.

    corbin
previous month march 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