In my iPhone application, I have a secondary thread that I have made for performing tasks in the background, and every few milliseconds, the view must be updated (not from the main thread). I have tried the following code in my UIView subclass:
[self performSelectorOnMainThread:@selector(setNeedsDisplay) withObject:nil waitUntilDone:NO];
That works great on the simulator, however, on my device, it is very laggy. The only thing I can think of is that the main thread is bogged up with the usual routines of the UIKit, meaning my setNeedsDisplay gets called long behind when it is supposed to (about 1/2 sec later). I think this because in other code, based off of user interaction, I call setNeedsDisplay right away, and it works fine without any lag at all. There are less backend computations on the secondary thread than there is on the user interface thread. This leads to some very bad visual effects in my application.
So, to sum things up, How can I fix this problem?
UPDATE:
Is there another way for me to tell a view it needs to refresh itself x times a second? that could end up being better performance for me, if that is possible. I have tried CADisplayLink with no success...
[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(setNeedsDisplay) userInfo:nil repeats:YES];
and it seems to work fine now. – Izaak