• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSTableView - need something like tableView:shouldSelectRow:byExtendingSelection:?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTableView - need something like tableView:shouldSelectRow:byExtendingSelection:?


  • Subject: Re: NSTableView - need something like tableView:shouldSelectRow:byExtendingSelection:?
  • From: Corbin Dunn <email@hidden>
  • Date: Fri, 3 Jun 2005 09:01:39 -0700

Matt,

I'd really like to see the final code for this. As I have lamented before...


Download Jim's demo:

http://homepage.mac.com/jimcorreia/tmp/TableViewSelectionTest.zip

And replace the contents of his "MyAppDelegate.m" with the code below. It should give the effect that Jim was talking about. An exercise for the reader is to make the code simpler :)

--corbin

#import "MyAppDelegate.h"

@implementation MyAppDelegate

- (BOOL)tableView:(NSTableView *)tableView shouldSelectRow:(int)row byExtendingSelection: (BOOL)extend
{
BOOL shouldSelect = YES;
if (extend) {
// If we are extending the selection, disallow if the proposed row is
// the first row, or the last row


        if ((row == 0) || (row == [tableView numberOfRows] - 1))
        {
            shouldSelect = NO;
        }

        // Disallow if the first or the last row are already selected

if (shouldSelect)
{
if (([tableView isRowSelected: 0]) ||
([tableView isRowSelected: [tableView numberOfRows] - 1]))
{
shouldSelect = NO;
}
}
}
return shouldSelect;
}


- (BOOL)tableView:(NSTableView *)tableView shouldSelectRow:(int)row {
    BOOL            shouldSelect = YES;

// the mouse will be dragging when we are extending the selection
BOOL selecting = [[NSApp currentEvent] type] == NSLeftMouseDragged;
if (selecting) {
// If we are extending the selection, disallow if the proposed row is
// the first row, or the last row


        if ((row == 0) || (row == [tableView numberOfRows] - 1))
        {
            shouldSelect = NO;
        }

        // Disallow if the first or the last row are already selected

if (shouldSelect)
{
if (([tableView isRowSelected: 0]) ||
([tableView isRowSelected: [tableView numberOfRows] - 1]))
{
shouldSelect = NO;
}
}
}
NSLog(@"shouldSelect %d: is %d", row, shouldSelect);


    return shouldSelect;
}


@end

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Re: NSTableView - need something like tableView:shouldSelectRow:byExtendingSelection:? (From: Matt Neuburg <email@hidden>)

  • Prev by Date: Re: CFMessagePortCreateLocal(): failed to name Mach port
  • Next by Date: Re: Setting the "Open with" attribute on a file
  • Previous by thread: Re: NSTableView - need something like tableView:shouldSelectRow:byExtendingSelection:?
  • Next by thread: CFMessagePortCreateLocal(): failed to name Mach port
  • Index(es):
    • Date
    • Thread