Re: NSTableView: column selection selects rows?
Re: NSTableView: column selection selects rows?
- Subject: Re: NSTableView: column selection selects rows?
- From: Alexander Lamb <email@hidden>
- Date: Fri, 2 Jun 2006 12:21:19 +0200
Hello list,
Ok, to summarize, I found the solution:
When a user clicks on a column, it of course does NOT select rows,
however, since the NSTableView is connected to an ArrayController,
upon reordering the rows (sorting) it will call "selectRowIndexes..."
in order to preserve the selection of the records.
Since I have changed the behavior of the function, it didn't preserve
correctly the selection.
The solution is to have my subclass become the delegate of itself.
(in the awakeFromNib)
Implement
- (void)tableView:(NSTableView *)tableView
mouseDownInHeaderOfTableColumn:(NSTableColumn *)tableColumn
and
- (void)tableView:(NSTableView *)tableView didClickTableColumn:
(NSTableColumn *)tableColumn
The first function will be called at the mouse down, the second when
everything is finished.
So I simply set an instance variable in the first function to tell
"selectRowIndexes..." that we are in column selection mode. In that
function I simply call the super implementation. In the second
function I reset the variable to revert to my new behavior.
Here is the code of the function:
- (void)selectRowIndexes:(NSIndexSet *)indexes byExtendingSelection:
(BOOL)extend
{
if(inColumnClickedMode)
{
[super selectRowIndexes:indexes byExtendingSelection:extend];
}
else
{
int l =[indexes count];
unsigned int buffer[l];
[indexes getIndexes:&buffer maxCount:[indexes count]
inIndexRange:nil];
if([indexes count] > 1)
[super selectRowIndexes:indexes byExtendingSelection:extend];
else if([[self selectedRowIndexes] containsIndex:[indexes
firstIndex]])
[self deselectRow:[indexes firstIndex]];
else
[super selectRowIndexes:indexes byExtendingSelection:YES];
}
}
--
Alexander Lamb
email@hidden
On Jun 1, 2006, at 12:12 PM, Alexander Lamb wrote:
Hello,
I am implementing the following method in a subclass of NSTableView:
- (void)selectRowIndexes:(NSIndexSet *)indexes byExtendingSelection:
(BOOL)extend
The idea is to handle myself the selection / deselection of rows.
Unfortunately, this method also gets called when I select a column
(to reorder). My table is connected to an array controller in a
CoreData application.
Is there a way to either:
a) know when it is a column being selected
b) prevent rows being selected when I click on a column (actually,
the method is called twice for each click on a column)
Thanks,
Alex
--
Alexander Lamb
email@hidden
_______________________________________________
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
_______________________________________________
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