Re: What to subclass in NSArrayController to enable immediate editing of added rows?
Re: What to subclass in NSArrayController to enable immediate editing of added rows?
- Subject: Re: What to subclass in NSArrayController to enable immediate editing of added rows?
- From: David Hirsch <email@hidden>
- Date: Tue, 01 Dec 2009 14:15:38 -0800
Here is the solution I've found to work: subclassing
NSArrayController's addObject. It does violate MVC in knowing about
the view, but for me that is a reasonable trade-off to avoid having a
bunch of different custom add: methods in my document subclass for
each table I have to deal with.
- (void) addObject:(id) newObject {
[super addObject:newObject];
//Retrieve an array of the objects in your array controller and
calculate
//which row your new object is in
NSArray *array = [self arrangedObjects];
int row = [array indexOfObjectIdenticalTo:newObject];
//Begin editing of the cell containing the new object
// NSIndexSet *indexes = [NSIndexSet indexSetWithIndex:row];
// [myTable selectRowIndexes:indexes byExtendingSelection:NO];
[myTable editColumn:0 row:row withEvent:nil select:YES];
}
The second- and third-from-last lines that are commented out are
intended to select the correct row prior to editing, as supposedly
required in the docs. They do not seem to actually be required,
whether or not "Select Inserted Objects" is checked in IB. I'll
probably leave them in for the sake of docs-obedience anyhow.
Thanks for the help.
-Dave
On Dec 1, 2009, at 2:05 PM, Sean McBride wrote:
On 12/1/09 1:51 PM, David Hirsch said:
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.
NSArrayController is a model-controller, seems a little odd to me that
you would want it to be aware of NSView instances. Not that MVC
must be
followed religiously, but still.
============================
Dave Hirsch
Associate Professor
Department of Geology
Western Washington University
persistent email: email@hidden
http://www.davehirsch.com
voice: (360) 389-3583
aim: email@hidden
vCard: http://almandine.geol.wwu.edu/~dave/personal/DaveHirsch.vcf
============================
_______________________________________________
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