• 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
NSArrayController using NSUserDefaults bindings NSTableView into edit mode after an insert or add
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSArrayController using NSUserDefaults bindings NSTableView into edit mode after an insert or add


  • Subject: NSArrayController using NSUserDefaults bindings NSTableView into edit mode after an insert or add
  • From: "Joe Roback" <email@hidden>
  • Date: Thu, 1 Feb 2007 02:34:22 -0700

Ok, I am struggled to come up with an elegant solution to this:

After inserting a new row into an NSTableView using Cocoa bindings, I
wanted the newly inserted row to be selected and in edit mode, just
like when you add a new playlist to iTunes, giving the user the first
chance to change "untitled item" to something meaningful.

Here is my solution, anyone know of a better way?

I subclassed NSArrayController. Overwrote 2 methods, newObject and
addObject and added a delegate method, objectAdded.

- (id)newObject
{
	id obj = [super newObject];
	[obj setValue:@"untitled item" forKey:@"column1key"];
	return obj;
}

- (void)addObject:(id)object
{
	[super addObject:object];

	if (delegate && [delegate respondsToSelector:@selector(objectAdded)]) {
		[delegate objectAdded];
	}
}

Now I set my AppController to be the delegate of my subclassed
NSArrayController and implement the objectAdded:

tableview and arrayController are connected in interface builder to
IBOutlets in my AppController class.

- (void)objectAdded
{
	[tableview selectRow:([[arrayController arrangedObjects] count] - 1)
byExtendingSelection:NO];
	[tableview editColumn:0 row:([[arrayController arrangedObjects]
count] - 1) withEvent:nil select:YES];
}

so if anyone has any comments or a better idea or direction, please
say so. thanks. much appreciated.


-- Joseph A. Roback <robackja (at) cs.arizona.edu>

Graduate Student
Department of Computer Science
University of Arizona
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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


  • Prev by Date: Re: Please can any one sugest or send me Email validation code.
  • Next by Date: iCal stop responding after exception.
  • Previous by thread: Re: Please can any one sugest or send me Email validation code.
  • Next by thread: iCal stop responding after exception.
  • Index(es):
    • Date
    • Thread