controller example works in IB but not in app
controller example works in IB but not in app
- Subject: controller example works in IB but not in app
- From: matt neuburg <email@hidden>
- Date: Thu, 22 Apr 2004 17:01:17 -0700
Here's a simple setup with controllers that works in IB but chokes in the
built app, and I'm trying to understand why. I'm sure there's a simple
reason... It may well have been explained here before, so forgive me for not
finding the explanation. This is almost (or perhaps exactly) the same as:
<
http://cocoa.mamasam.com/MACOSXDEV/2004/02/2/84555.php>
But I didn't understand mmalc's answer there, as we shall see.
Work in IB. Make a table with one column, in a window. Make an
NSArrayController. Bind the table column's value to the NSArrayController's
arrangedObjects.thing (or whatever name suits you).
Now let's add an Add button. So, make the button in the window, and make its
action be the NSArrayController's add: method.
Now bind the NSArrayController's contentArray to Shared User Defaults,
values.stuff (or whatever name you like).
Run the interface within IB. It works great. You can add rows, you can edit
them, and they are remembered between runs. Cool!
Now go to Xcode and build-and-run the app. You can add a row, but when you
try to edit it and hit Tab to set the edit, you get an exception.
-[NSCFDictionary setObject:forKey:]: mutating method sent to immutable
object
mmalc says, both in the above thread and at his site, "collections retrieved
from user defaults are immutable, so if you're storing lists in user
defaults you may have to create mutable copies before you can modify them".
And he gives some code for modifying the binding for an object to insert a
data transformer that does this. But what I really don't get is: if I'm
doing it wrong, then why does it work so perfectly in IB? Is that a bug? Thx
- m.
--
matt neuburg, phd = email@hidden,
http://www.tidbits.com/matt/
pantes anthropoi tou eidenai oregontai phusei
AppleScript: the Definitive Guide! NOW SHIPPING...! (Finally.)
http://www.amazon.com/exec/obidos/ASIN/0596005571/somethingsbymatt
Subscribe to TidBITS! It's free and smart.
http://www.tidbits.com/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.