Re: bindings from threads
Re: bindings from threads
- Subject: Re: bindings from threads
- From: Ryan Britton <email@hidden>
- Date: Thu, 5 Oct 2006 11:33:00 -0700
The approach to take has two parts. Since bindings are typically
used to update UI widgets, the update notifications need to be called
on the main thread. A typical update may look something like this:
[self performSelectorOnMainThread:@selector(willUpdateValueForKey:)
withObject:@"someKey" waitUntilDone:YES];
//Update the value for someKey
[self performSelectorOnMainThread:@selector(didUpdateValueForKey:)
withObject:@"someKey" waitUntilDone:YES];
That handles the first part. For the second part you need to make
sure your accessors are threadsafe. You can either accomplish this
with locks or any of the other various thread safety directives or
ensure that values are only updated on the main thread.
On Oct 5, 2006, at 10:47 AM, Jim Thomason wrote:
I have an app that's using bindings and an array controller to manage
data in an NSTableView. It's a networked app that brings in data from
the net and tosses it into the array, which should then be
automatically reflected in the view.
First question is, I tend to get seemingly random crashes when it does
the refresh. Some of the time it'll work, some of the time it won't.
I'm manually handling the binding notifications here, along these
lines:
[self willUpdateValueForKey:@"myArray"];
//interesting things, receive data, add on to myArray
[self didUpdateValueForKey:@"myArray"];
I've found that I can eliminate these crashes by instead accumulating
into a new array, then adding on those array elements to my master
array and sending my notifications from the main thread, instead of my
watcher thread.
Is this expected behavior? Should I not be able to do this from a
secondary thread and only from the main thread? Or does this indicate
that something else is going on?
Secondly, is this the best way to do something like this? I don't want
to fall back to the old way of using the data source and doing it all
manually, but I would be interested in other binding approaches.
Alternatively, I know that I can add an IBOutlet to my array
controller and use that to just add the objects and not worry about
the bindings notes. Would one way be preferrable to another? Which
would be a more common approach?
Thanks,
-Jim....
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden