Re: NSTableView select a single cell
Re: NSTableView select a single cell
- Subject: Re: NSTableView select a single cell
- From: Lorenzo <email@hidden>
- Date: Tue, 05 Jun 2007 00:06:18 +0200
Hi Sergey,
thanks, it's exactly what I have done.
I detect the clicked cell from my subclassed NSTableView mouseDown and
mouseUp using rowAtPoint and columnAtPoint.
Then in the delegate method tableView: willDisplayCell:
I set the selection to the cell with
colIndex = [[aTableColumn identifier] intValue];
selRow = [aTableView mSelectedRow];
selCol = [aTableView mSelectedCol];
isCellSelected = (rowIndex == selRow && colIndex == selCol);
[(MYCell*)aCell setSelected:isCellSelected];
I subclass the NSCell and draw the image and the text dividing the cell rect
within the drawWithFrame:inView:. If the cell is selected I draw a border.
Fine.
It works pretty well, but I had to override this method in the delegate
- (BOOL)selectionShouldChangeInTableView:(NSTableView *)aTableView
{
return NO;
}
otherwise anytime I click a row I see the blue selection color over the row.
Best Regards
--
Lorenzo
email: email@hidden
> From: Sergey Shapovalov <email@hidden>
> Date: Mon, 04 Jun 2007 10:03:38 +0400
> To: Lorenzo <email@hidden>
> Cc: Cocoa-Dev Apple <email@hidden>
> Subject: Re: NSTableView select a single cell
>
>
> On Jun 2, 2007, at 7:17 PM, email@hidden wrote:
>
>> Hi,
>> I have a NSTableView with 3 columns. Each column datCell is set to my
>> subclass of NSTextFieldCell, so I can set text + image in each
>> single cell.
>> Well, it works. Now, I would like the user clicks on a single cell
>> and see
>> ONLY that cell selected and highlighted. Instead I cannot get rid
>> of the
>> whole row selection made automatically by NSTableView.
>> Any idea?
>>
> Well, if I had to implement the behavior you desire, I'd try:
> a) implementing a custom cell class;
> b) overriding mouseDown and mouseUp for the table control.
>
> In mouseDown and mouseUp, I'd figure out what cell should be selected
> (from the coordinates of the point where the click happened - can get
> them from the event). In my custom cell class, I'd implement custom
> drawing procedure (override drawWithFrame:inView:) to draw different
> background for selected and non-selected cells. Not to mention that
> image+text cells itself do require using custom NSCells; here is a
> good starting point provided by Apple (ImageAndTextCell.m):
> http://developer.apple.com/samplecode/ImageBackground/listing4.html
>
> Best regards,
> Sergey.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden