Initial Object in Array Controller
Initial Object in Array Controller
- Subject: Initial Object in Array Controller
- From: David Mirabito <email@hidden>
- Date: Thu, 29 Sep 2011 10:42:13 +0100
Hello,
I've a simple application which for now just shows a tableview with a list of expenses ...
NSArrayController (many of these are just the default...)
Avoid Empty Selection - NO
Preserve Selection - NO
Select Inserted Objects - YES
Clear Filter Predicate on Insert - YES
Auto Rearrange Content - YES
Always Use Multi Value Marker - NO
Mode - Class
ClassName - DJMExpense
PreparesContent - YES
Editable - YES
No bindings configured in IB, but is connected to an outlet in MyDocument.m, and columns in the tableview are appropriately bound to the arrangedObjects.Name, etc as required.
My understanding is that because of 'preparesContent=YES' it manages the array internally, which i get at with the [myController content].
This all works fine - I can add and remove new items via pushbuttons, view then in the TableView, etc.
The only odd thing is that there is always a single, default item there when a new document is created. All my expense creations happen with +[DJMExpense expenseWithName:Amount] and if I place a breakpoint on -[DJMExpense init] I see the following backtrace:
#0 -[DJMExpense init] (self=0x1001f41f0, _cmd=0x7fff9415b620) at /Users/davidm/Desktop/Code/test/test/DJMExpense.m:25
#1 0x00007fff93da58db in -[NSObjectController newObject] ()
#2 0x00007fff93da5833 in -[NSObjectController prepareContent] ()
#3 0x00007fff91e549e1 in -[NSObject performSelector:] ()
#4 0x00007fff91e54962 in -[NSSet makeObjectsPerformSelector:] ()
#5 0x00007fff938e7c27 in -[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:] ()
#6 0x00007fff938de1b9 in loadNib ()
#7 0x00007fff938dd6b6 in +[NSBundle(NSNibLoading) _loadNibFile:nameTable:withZone:ownerBundle:] ()
#8 0x00007fff938dd5d1 in +[NSBundle(NSNibLoading) loadNibFile:externalNameTable:withZone:] ()
#9 0x00007fff93acb328 in -[NSWindowController loadWindow] ()
#10 0x00007fff93acb0e3 in -[NSWindowController window] ()
#11 0x00007fff93b3ffb0 in -[NSDocument windowForSheet] ()
#12 0x00007fff93acaa33 in -[NSDocument _shouldShowAutosaveButtonForWindow:] ()
#13 0x00007fff93aca6e2 in -[NSWindowController setDocument:] ()
#14 0x00007fff93c7ef4a in -[NSDocument makeWindowControllers] ()
#15 0x00007fff93b3fda3 in -[NSDocument(NSPersistentUISupport) restoreDocumentWindowWithIdentifier:state:completionHandler:] ()
#16 0x00007fff93b3fcf8 in -[NSDocumentControllerPersistentRestoration loadedDocument:forAutoID:] ()
#17 0x00007fff93b3f80c in __-[NSDocumentController reopenDocumentForURL:withContentsOfURL:display:completionHandler:]_block_invoke_8 ()
#18 0x00007fff93b2b558 in __-[NSDocumentController reopenDocumentForURL:withContentsOfURL:display:completionHandler:]_block_invoke_5 ()
#19 0x00007fff93b2b4a3 in __-[NSDocumentController reopenDocumentForURL:withContentsOfURL:display:completionHandler:]_block_invoke_4 ()
#20 0x00007fff93b2b1e5 in -[NSDocumentController _openDocumentWithContentsOfURL:usingProcedure:] ()
#21 0x00007fff93b2add1 in __-[NSDocumentController reopenDocumentForURL:withContentsOfURL:display:completionHandler:]_block_invoke_3 ()
#22 0x00007fff9141390a in _dispatch_call_block_and_release ()
#23 0x00007fff9141577a in _dispatch_main_queue_callback_4CF ()
#24 0x00007fff91df2c0c in __CFRunLoopRun ()
#25 0x00007fff91df2216 in CFRunLoopRunSpecific ()
#26 0x00007fff95afc4ff in RunCurrentEventLoopInMode ()
#27 0x00007fff95b03c21 in ReceiveNextEventCommon ()
#28 0x00007fff95b03aae in BlockUntilNextEventMatchingListInMode ()
#29 0x00007fff938d6191 in _DPSNextEvent ()
#30 0x00007fff938d5a95 in -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] ()
#31 0x00007fff938d23d6 in -[NSApplication run] ()
#32 0x00007fff93b5052a in NSApplicationMain ()
#33 0x0000000100001492 in main (argc=2, argv=0x7fff5fbff968) at /Users/davidm/Desktop/Code/test/test/main.m:13
So apparently the NIB loading machinery is creating a new expense object and placing it into the ArrayController's content? Why would this be so? The object behaves just like any other, in that I can edit it in the tableview and/or remove via a button wired to [myArrayController remove:].
Ideally the array should be completely empty in a new document, and is up to the user's interaction to place the first object. What must I do to avoid this auto-creation of the object?
Thanks,
DavidM
ps - please just let me know if I can share more details to help diagnose anything ...
_______________________________________________
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