Re: Editing an NSOutlineView item
Re: Editing an NSOutlineView item
- Subject: Re: Editing an NSOutlineView item
- From: Luther Baker <email@hidden>
- Date: Mon, 27 Oct 2014 21:07:59 -0500
Thanks Ken. Just what I needed.
-Luther
On Mon, Oct 27, 2014 at 7:47 PM, Ken Thomases <email@hidden> wrote:
> On Oct 27, 2014, at 7:02 PM, Luther Baker <email@hidden> wrote:
>
> > I've successfully built an NSOutlineView and configured the items for
> > editing. Got that working.
> >
> > Now, in my delegate/datasource, I am implementing
> >
> > - (BOOL)outlineView:(NSOutlineView *)outlineView
> > shouldEditTableColumn:(NSTableColumn *)tableColumn
> > item:(id)item {
> > NSLog(@"hi");
> > }
> >
> > but when I tap on a field a 2nd time to edit it - this never gets
> invoked.
>
> I'm guessing that you're using a view-based outline view (as you should,
> since it's the modern way). The above method is only used for NSCell-based
> outline views. This is not as clearly documented as it should be. The
> corresponding method for NSTableView is clearly documented as only valid
> for NSCell-based table views.
>
> In a view-based outline view, the individual views within the cells of the
> outline view act (almost) just like views elsewhere. An NSTextField
> controls its own editability. You can use bindings to control the text
> field's editability or you can set its editable property as conditions
> warrant.
>
> The outline view is involved in a less direct manner. Its implementation
> of -validateProposedFirstResponder:forEvent: is called and can control
> whether the text field can become first responder, a.k.a. begin editing.
>
>
> > I am also implementing
> >
> > - (void)outlineView:(NSOutlineView *)outlineView
> > setObjectValue:(id)object
> > forTableColumn:(NSTableColumn *)tableColumn
> > byItem:(id)item {
> > NSLog(@"hi");
> > }
> >
> > but once I replace the text of the field and hit enter, this is not
> called
> > either. Is there something else I must to do get complete editing
> > capability?
>
> Again, this is not used for view-based outline views and this is most
> clearly documented for the corresponding table view method. You can use
> bindings to tie the text field's value to a key path of the object
> associated with the cell or you can use target-action to trigger a method
> when the text field's value has changed.
>
>
> > Also, 1 final trivial question ... let's say I want to allow editing ONLY
> > after right clicking and picking a context menu item. Assuming I can get
> > the row and column from the event, how do I programmatically turn the
> > editor on for a specific field?
>
> The traditional way is to use -editColumn:row:withEvent:select:, but it's
> more complicated with view-based outline views. That method will attempt
> to make the cell view the first responder. Not all views accept first
> responder and support a notion of editing when they are first responder.
> For example, NSTableCellView does not, and that's commonly used as the cell
> view.
>
> If you use a bare NSTextField as the cell view, then the above method will
> work directly because the text field will accept first responder and begin
> editing (assuming it's editable).
>
> If you're using a compound cell view and you want to initiate editing on a
> particular text field within it, you should make it first responder
> directly:
>
> NSTableCellView* tableCellView = [outlineView viewAtColumn:column
> row:row makeIfNecessary:NO];
> NSTextField* textField = tableCellView.textField;
> if ([textField acceptsFirstResponder])
> [textField.window makeFirstResponder:textField];
>
> You may also want to select the row and scroll it into view.
>
> Regards,
> Ken
>
>
_______________________________________________
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