Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.
OK - I have a loop that needs to repeatedly call setBackgroundColor on a UIImageView using a series of different periods. If you were to imaging a morse code flasher, you'd be along the same lines with the dots and dashes being different lengths, along with a predefined "gap" in the middle. The problem is the loop doesn't give the view time to actually process the call - so I'm scratching my head over which way to do this.
Two ways I've come up with is pre-scheduling an NSTimer to fire at all the future points, or to use an NSThread to fire over and over and then switch the view...
Both ways appear in my head to be a bit complicated - but bare in mind the 20 years of VB "training" I had before starting with Objective-C a few years back.
Update: So, I tried putting the task code into a dispatch queue. It ran identical to how it did in the loop, in that the screen still had no chance to catch up and process the setBackgroundColor messages...
Update: So, I tried putting the task code into a dispatch queue. It ran identical to how it did in the loop, in that the screen still had no chance to catch up and process the setBackgroundColor messages...
*scratches head*
Will go back to the drawing board.
Cheers,
Coulls
You're not supposed to make UI changes except from the main thread. If you want to control everything from a worker thread, use performSelectorOnMainThread from the worker thread to get the main thread to update the UI.
Another way to do this without using threads is to use the method performSelector:withObject:afterDelay.
You could fire off the same method with different delays, and have the method change the color as needed.
The code below assumes you have an outlet theView to the view who's background color you want to change, an integer instance variable colorIndex, and another NSArray instance variable colorsArray that contains an array of UIColor objects:
-(void) beginFlashing; { colorIndex = 0; int index; int count = 10; //Create a C array of different delays for the different steps. //We could also use an NSArray of NSNumbers. I was just lazy. float[] delays = {0.2, 0.3, 0.5, 0.9, 1.0, 1.5, 1.9, 2.2, 2.7, 3.0}
for (index = 0; index < count; index++) { [self performSelector: @selector(nextColor) withObject: nil afterDelay: delays[index] ]; }
Regards,
Duncan C WareTo
Animated GIF created with Face Dancer, available for free in the app store.
You're not supposed to make UI changes except from the main thread. If you want to control everything from a worker thread, use performSelectorOnMainThread from the worker thread to get the main thread to update the UI.[/CODE]
Doh! Now I feel like a twit... Will try again tonight and let you know how it pans out...
Replies
*scratches head*
Will go back to the drawing board.
Cheers,
Coulls
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like AwesomeAnother way to do this without using threads is to use the method performSelector:withObject:afterDelay.
You could fire off the same method with different delays, and have the method change the color as needed.
The code below assumes you have an outlet theView to the view who's background color you want to change, an integer instance variable colorIndex, and another NSArray instance variable colorsArray that contains an array of UIColor objects:
Duncan C
WareTo
Animated GIF created with Face Dancer, available for free in the app store.
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like AwesomeThanks!
Jase
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like Awesome