Re: Table Data and NSArrayController
Re: Table Data and NSArrayController
- Subject: Re: Table Data and NSArrayController
- From: email@hidden
- Date: Wed, 24 Dec 2003 00:28:50 -0500
Thanks for the reply,
I don't think that this is the case, or at least the whole case. I can
still add anything to the NSArrayController. I overrode the add: method
with:
- (void)add: (NSObject*)sender
{
[self addObject: @"Hello"];
}
which successfully adds a Hello to the table and to the preferences. I
think the problem is that the content of the NSStrings (that's the
data) cannot be modified. I decided to then encapsulate the NSStrings,
making them a variable in a class, so that a more proper binding path
could be made with keys in interface builder rather than dealing
directly with objects, but these classes can't be written to file, so I
made a transformer that simply takes an array of strings and converts
it to an array of string encapsulators and vice versa: The code is as
follows:
- (id)transformedValue:(id)value
{
NSLog([value description]);
if ([value isKindOfClass: [NSString class]])
return [Encapsulator encapsulatorWithString: value];
else if ([value isKindOfClass: [NSArray class]])
{
NSMutableArray* array = [NSMutableArray array];
NSEnumerator* valueEnumerator = [value objectEnumerator];
while (NSString* valueString = [valueEnumerator nextObject])
{
[array addObject: [Encapsulator encapsulatorWithString:
valueString]];
return array;
}
}
return nil;
}
However, nothing is done because the value is of type:
_NSControllerObjectProxy
What am I to do? For every great thing that you can do with the
controller layer, there are two extremely annoying inhibitors.
On 23 Dec 2003, at 6:07 PM, Scott Anguish wrote:
>
Yep... here's the problem.
>
>
You've got a NSMutableArray that you're storing the array of strings
>
in. This array is written to the user defaults.
>
>
When you read the array from user defaults, you are not getting a
>
mutable array, you're getting an immutable array. So, when you try to
>
make changes, you get hosed.
>
>
You either need to convert that data to a mutable array through a
>
value transformer, or write the data out using the value transformer
>
NSUnarchivedData. The first would be better in defaults as it would
>
be easily editable, but would require you to write the transformer
>
(not that it would be a huge effort). The second would require no
>
coding, but you're defaults get more obscured in the file (which may
>
not be a bad thing)
_______________________________________________
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.