• 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: Making NSTableView Cells Selectable, But Not Editable
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Making NSTableView Cells Selectable, But Not Editable


  • Subject: Re: Making NSTableView Cells Selectable, But Not Editable
  • From: Mike Wright <email@hidden>
  • Date: Wed, 28 Jun 2006 17:50:30 -0500

On 27 Jun 2006 10:27:20 -0700, Matt Neuburg <email@hidden> wrote:

(I thought I'd try this again on a weekday.)

I have a window containing an NSTableView. I have a controller object
set as delegate for the table view, but have not subclassed the table
view.

The following applies to the IBAction method that is called whenever
the table is clicked.

I look at a BOOL to decide whether to keep the user from editing cells
in the table view. However, the cell content needs to remain
selectable for copying or for dragging to other windows.


I can't use -tableView:shouldEditTableColumn:row:, because returning
NO to that apparently prevents cell selection as well as editing.
NSTableColumn -setEditable: causes the same problem.

As this is only called after the table view field editor has become
the first responder, I use the following line to get the current
cell text:

NSTextView *textView = (NSTextView *)[[editorWindowController
window] firstResponder];

Then, if required by my BOOL, I say:

[textView setEditable:NO];

This works just fine if the user single-clicks in a cell. The cell
becomes active, but the text is not automatically selected. The text
is selectable, so it can be copied or dragged, but is not editable,
so it can't be changed.

The problem arises when the user double-clicks in a cell. The cell
content is selected automatically and is editable. (This is not
disastrous, because the document associated with the table view
cannot be saved, but it's still misleading and potentially confusing
to the user.)

Just hacking around, I've also tried adding the following lines,
which don't seem to have any effect, either:

[tableView setIgnoresMultiClick:YES];
[tableView setDoubleAction:nil];

In this same action method, I also set a link attribute if the cell
contains a URL. This works as expected when I single-click; the URL
text becomes blue and underlined. When I double-click a cell that
contains a URL, however, I can see the text going blue and underlined
while the background remains white, but then the text goes plain
again and becomes selected. So, it appears that the double-click is
causing something to happen following my action method, which is
undoing my attempts to make the cell uneditable--and redrawing the
cell in the process.

How do I prevent this? Do I have to subclass my NSTableView? If so,
in which method would I do it? -doubleAction: is called "when the
user double-clicks a column header or an uneditable cell", and my
cells are not technically "uneditable"--or are they? I think I'm
beginning to get confused...

What have I missed in all this mess?

Why don't you just implement control:textShouldBeginEditing: and return the
value of your boolean?

Thanks, Matt, that's what I was looking for. I wasn't looking beyond NSTableView in the docs. I need to sharpen up my doc-searching skills.


PS. It also happens that in your app (iData 2) single-clicking a row
automatically makes that cell editable (and you can't cancel out of this
situation by hitting Return). I've lost a lot of data because I clicked on
row and then happened to start typing, accidentally wiping out what was in
the cell. In my view, a cell should not become editable unless the user does
something explicit (e.g. double-clicks). Fixing this might be better both
for the user and for the programmer. :)

I assume you're referring to the cell text being selected when clicking in a field name in Basic View? That's a "feature" that has been there for over ten years, going back through iData Pro to InfoGenie, so I'm not quite ready to drop it entirely, but I might add yet another preference to turn that behavior off. (Undo should work, as long as you don't leave the cell.)


Thanks again,
Mike
http://www.idata2.com
http://www.raccoonbend.com
_______________________________________________
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


  • Prev by Date: Re: How to debug during Unit Test (otest)
  • Next by Date: Re: Beginner Question About CustomView, -drawRect: and Plotting Data.
  • Previous by thread: Re: Making NSTableView Cells Selectable, But Not Editable
  • Next by thread: how do get contentView of a NSOpenPanel and run it inside another window?
  • Index(es):
    • Date
    • Thread