Re: NSTableView - need something like tableView:shouldSelectRow:byExtendingSelection:?
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