Well, that is a nice bit of code to have, but it doesn't really address the issue. As I wrote in my original post, there are a number of published methods for handing this in (for example) the NSDocument subclass. What *I* want to do is handle it in my NSArrayController subclass, for encapsulation purposes - I have a number of different tables for which I want to enable this, and I'd like to keep the functionality separate. I am looking into the suggestion of subclassing NSArrayController's addObject: method, which seems likely to work.

Also, the scrollRowToVisible call is superfluous, since the editColumn:row:withEvent:select: method is documented to do the scrolling for you already. And, I think the setSelectedObjects can be replaced by a checkbox in IB, right? (Although perhaps under some circumstances you would not like the added row to be selected?)
-Dave

On Dec 1, 2009, at 1:44 PM, Sean McBride wrote:

On 11/30/09 7:57 PM, David Hirsch said:

I'm trying to have my table immediately enable editing of added
items.

I have a handy NSTableView category to do that:

- (void)makeEditableSelectedCellOfColumnIdentifier:(NSString*)
inColumnIdentifier
{
NSTableColumn* column = [self tableColumnWithIdentifier:inColumnIdentifier];
        if (column && ![column isHidden])
        {
                if ([self numberOfSelectedRows] == 1)
                {
NSInteger columnIndex = [self columnWithIdentifier:inColumnIdentifier];
                        NSInteger selectRowIndex = [self selectedRow];
                        if ((columnIndex != -1) && (selectRowIndex != -1))
                        {
[self editColumn:columnIndex row:selectRowIndex withEvent:nil select:YES];
                        }
                }
        }
}

So in response to some "add" button in the UI, I have an action method
that does:

foo = [arrayController newObject]
[arrayController setSelectedObjects:[NSArray arrayWithObject:foo]]
[tableView scrollRowToVisible:[tableView selectedRow]];
[tableView makeEditableSelectedCellOfColumnIdentifier:@"bar"];

hth,

--
____________________________________________________________
Sean McBride, B. Eng                 s...@rogue-research.com
Rogue Research                        www.rogue-research.com
Mac Software Developer              Montréal, Québec, Canada




============================
Dave Hirsch
Associate Professor
Department of Geology
Western Washington University
persistent email: dhir...@mac.com
http://www.davehirsch.com
voice: (360) 389-3583
aim: dhir...@mac.com
vCard: http://almandine.geol.wwu.edu/~dave/personal/DaveHirsch.vcf
============================



_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to