• 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 selecting text within a cell [SOLUTION]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTableView selecting text within a cell [SOLUTION]


  • Subject: Re: NSTableView selecting text within a cell [SOLUTION]
  • From: Ben Golding <email@hidden>
  • Date: Tue, 1 Feb 2011 16:50:18 +1100

On 31/01/2011, at 16:30, Ben Golding wrote:

> I have an app with a NSTableView where the data is presented to the user.  When the user hits "Find", I'd like to be able to scroll the table view to the visible cell (easy enough) and then select the range that matched within that field (not so easy).
>
> At present, my code looks like:
>
> NSCell *cell = [csvTableView preparedCellAtColumn:col row:row];
> NSText *textEditor = [csvWindow fieldEditor:YES forObject:cell];
>
> NSLog(@"Match: row %@, field %@, range(%d, %d)", [match row], [match field], [match range].location, [match range].length);
> [csvTableView scrollRowToVisible:row];
> [csvTableView scrollColumnToVisible:col];
> [textEditor setSelectedRange:[match range]];
>
> I feel like I need to between getting the textEditor for the window and calling -setSelectedRange:, I just don't know what.

I got a really great answer from Corbin Dunn who explained that what I was doing was not giving me what I wanted: asking for a field editor for the cell wasn't sensible; what I really wanted was the field editor for the control, ie the tableView.

In essence he suggested I should change my code to:

    NSText *textEditor;

    [csvTableView editColumn:col row:row withEvent:nil select:NO];
    textEditor = [csvWindow fieldEditor:YES forObject:csvTableView];
    [textEditor setSelectedRange:[match range]];

which is not just shorter, it works!

	Ben.

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please 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

References: 
 >NSTableView selecting text within a cell (From: Ben Golding <email@hidden>)

  • Prev by Date: Re: text orientation/positioning with layout manager
  • Next by Date: array controllers and key paths
  • Previous by thread: Re: NSTableView selecting text within a cell
  • Next by thread: Tab bar controller inside a navigation controller, how to adjust the view height
  • Index(es):
    • Date
    • Thread