FROM : Miguel Coxo
DATE : Wed Jan 30 22:16:23 2008
Ty i will try that and post the result back =)
I did use this one* to notify the Controller of changes, maybe it will also
work for changing just values =).
*
* "Mutate the result of [self mutableArrayValueForKey:] rather than
directly mutating the array."
*
On Jan 30, 2008 8:07 AM, Ken Thomases <<email_removed>> wrote:
> On Jan 29, 2008, at 6:16 PM, Miguel Coxo wrote:
>
> > Hello, so i have one ArrayController that is bound to one Array, and a
> > tablecolumn that is bound to the ArrayController objects (not any
> > particular
> > value).
> >
> > As a normal behavior the controller gets notified when i add or remove
> > objects, but i have a thread that every second updates the objects.
> > What is
> > the correct way to notify the Controller that a specific object
> > values where
> > changed?
> >
> > I'm guessing the Thread shouldn't have direct access to the
> > Controller since
> > its in a "lower" abstraction layer, so how do i notify or make the
> > controller track changes to values?
> >
> > The column is not bound to values because it has custom dataCells
> > that need
> > several properties from the array objects.
>
> If you modify the array in one of the KVO-compliant ways, then the
> array controller will be informed automatically. However, you should
> not do so from a background thread, because the notification will be
> delivered on whatever thread does the modification, and bindings will
> attempt to update the GUI from the background thread, which will cause
> trouble.
>
> You can use performSelectorInMainThread:... to have the background
> thread push the modification to the main thread. You may not need to
> use a thread at all. Will an NSTimer meet your needs?
>
> To perform the modification in a KVO-compliant way, you should use one
> of the following techniques:
>
> a) [self insertObject:in<Key>AtIndex:]
>
> b) [self removeObjectFrom<Key>AtIndex:]
>
> c) [self replaceObjectIn<Key>AtIndex:withObject:]
>
> d) Mutate the result of [self mutableArrayValueForKey:] rather than
> directly mutating the array.
>
> e)
> [self willChange:valuesAtIndexes:forKey:]
> // mutate the array directly
> [self didChange:valuesAtIndexes:forKey:]
>
> f) Replace the array whole with [self set<Key>:] or [self
> setValue:forKey:]
>
>
> -Ken
>
--
Cumprimentos, Miguel Coxo.
DATE : Wed Jan 30 22:16:23 2008
Ty i will try that and post the result back =)
I did use this one* to notify the Controller of changes, maybe it will also
work for changing just values =).
*
* "Mutate the result of [self mutableArrayValueForKey:] rather than
directly mutating the array."
*
On Jan 30, 2008 8:07 AM, Ken Thomases <<email_removed>> wrote:
> On Jan 29, 2008, at 6:16 PM, Miguel Coxo wrote:
>
> > Hello, so i have one ArrayController that is bound to one Array, and a
> > tablecolumn that is bound to the ArrayController objects (not any
> > particular
> > value).
> >
> > As a normal behavior the controller gets notified when i add or remove
> > objects, but i have a thread that every second updates the objects.
> > What is
> > the correct way to notify the Controller that a specific object
> > values where
> > changed?
> >
> > I'm guessing the Thread shouldn't have direct access to the
> > Controller since
> > its in a "lower" abstraction layer, so how do i notify or make the
> > controller track changes to values?
> >
> > The column is not bound to values because it has custom dataCells
> > that need
> > several properties from the array objects.
>
> If you modify the array in one of the KVO-compliant ways, then the
> array controller will be informed automatically. However, you should
> not do so from a background thread, because the notification will be
> delivered on whatever thread does the modification, and bindings will
> attempt to update the GUI from the background thread, which will cause
> trouble.
>
> You can use performSelectorInMainThread:... to have the background
> thread push the modification to the main thread. You may not need to
> use a thread at all. Will an NSTimer meet your needs?
>
> To perform the modification in a KVO-compliant way, you should use one
> of the following techniques:
>
> a) [self insertObject:in<Key>AtIndex:]
>
> b) [self removeObjectFrom<Key>AtIndex:]
>
> c) [self replaceObjectIn<Key>AtIndex:withObject:]
>
> d) Mutate the result of [self mutableArrayValueForKey:] rather than
> directly mutating the array.
>
> e)
> [self willChange:valuesAtIndexes:forKey:]
> // mutate the array directly
> [self didChange:valuesAtIndexes:forKey:]
>
> f) Replace the array whole with [self set<Key>:] or [self
> setValue:forKey:]
>
>
> -Ken
>
--
Cumprimentos, Miguel Coxo.
| Related mails | Author | Date |
|---|---|---|
| MagmaRules | Jan 29, 22:21 | |
| Miguel Coxo | Jan 30, 01:16 | |
| Ken Thomases | Jan 30, 09:07 | |
| Miguel Coxo | Jan 30, 22:16 | |
| Ken Thomases | Jan 31, 01:41 | |
| Miguel Coxo | Jan 31, 23:37 |






Cocoa mail archive

