NSValueTransformer can I add more objects to the bound array?

261 views Asked by At

I'm using a value transformer to transform the content array of a table content "bound" so I can edit the values before it pass to the views and it works

- (id)transformedValue:(id)value
{
    NSArray *oldArr = value;
    NSMutableArray *newArr = [[NSMutableArray alloc] init];
    for(Metadata *meta in oldArr)
    {
        meta.title = @"hello";
        [newArr addObject:meta];
        [newArr addObject:meta];
    }
    return newArr;
}

the edit in values works, and reflecting in the UI

meta.title = @"hello";

BUT when I try to expand the array, instead of bound the table to an array of size 2, I want to expand it to be of size 4, by just duplicating them

for(Metadata *meta in arr)
{
    meta.title = @"hello";
    [newArr addObject:meta];
    [newArr addObject:meta];
}

This isn't working and I got cells count of the old array how I can achieve what I want??

thanks

1

There are 1 answers

0
Wil Shipley On

I’m not at all clear on why you’re doing this, and it sounds a bit like a bad idea, but I’ve subclassed NSArrayController before to add extra items. In your case you could just set up the NSArrayController and stick in whatever you wanted (duplicated items) and hook the tableView (is that what you’re using?) to the NSArrayController.