On 22 Sep, 2009, at 09:12, BareFeet wrote:

Hi all,

I have an NSArrayController and am trying to get an "add" button to work, so that it inserts a new DataRow object at the current selection, or at the end if no selection.

Here's my code:

- (IBAction) insertDataRow:(id)sender
{
        DataRow* newDataRow = [[DataRow new] autorelease];
[newDataRow setTransactionPending:@"insert"]; // just a flag in the DataRow object NSUInteger controllerSelectionIndex = [dataRowsController selectionIndex];
        
        if (controllerSelectionIndex == NSNotFound)
        {
                [dataRowsController addObject:newDataRow];
        }
        else
        {
[dataRowsController insertObject:newDataRow atArrangedObjectIndex:controllerSelectionIndex];
        }
}

When it gets to either the addObject or insertObject method, it crashes with the error:
Program received signal:  “EXC_BAD_ACCESS”

If I hook up an add button directly to the "insert" or "remove" received action of the NSArrayController, it works fine. But I need to run my own method so I can check and set other variables, such as the setTransactionPending property shown above.

Can someone please tell me what I'm doing wrong?

Dave responded to that. I just thought I'd mention this (from 'Cocoa Bindings Programming Topics')

"If the controller is in object mode, the method newObject is used to create new objects. The default implementation simply allocates a new object of the class specified by objectClass or theentityName and sends the object a standard init message with no arguments. If your content objects require more complex initialization, you can subclass the appropriate controller class and override the newObject method."

--colin_______________________________________________

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