Thanks Ken. Just what I needed. -Luther
On Mon, Oct 27, 2014 at 7:47 PM, Ken Thomases <k...@codeweavers.com> wrote: > On Oct 27, 2014, at 7:02 PM, Luther Baker <lutherba...@gmail.com> 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 (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com