 |
 |
|
 |
04-25-2009, 08:16 PM
|
#1 (permalink)
|
|
Registered Member
Join Date: Mar 2009
Posts: 161
|
proper use of nstimer...
I just want to implement a small delay.. so is it "ok" to do the following?
Code:
[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(timerUpdate) userInfo:nil repeats:NO];
while(!done); //wait here until timerUpdate sets flag to done..
//continue program..
Ok, basically I am setting up the timer, but all I want is to delay, so I loop until the timerUpdate function sets the 'done' property..
can i loop like that? is that "ok"? thx
|
|
|
04-25-2009, 08:34 PM
|
#2 (permalink)
|
|
New Member
Join Date: Jan 2009
Location: San Diego, CA
Posts: 405
|
That's really not cool, as you are eating CPU time in the loop.
IF it works at all, as I don't think any framework will call a delegate except during the message loop. By looping inside your code, you are not allowing the message loop to run.
Why not just sleepForTimeInterval?
Last edited by jtara; 04-25-2009 at 08:36 PM.
|
|
|
04-25-2009, 08:47 PM
|
#3 (permalink)
|
|
Registered Member
Join Date: Mar 2009
Posts: 161
|
Quote:
Originally Posted by jtara
That's really not cool, as you are eating CPU time in the loop.
IF it works at all, as I don't think any framework will call a delegate except during the message loop. By looping inside your code, you are not allowing the message loop to run.
Why not just sleepForTimeInterval?
|
I haven't heard of that one... I will try it... I am "flipping" cards over and I want there to be a 1/3 second delay between each one, will sleepfortimeinterval work for that?
|
|
|
04-25-2009, 10:51 PM
|
#4 (permalink)
|
|
New Member
Join Date: Jan 2009
Location: San Diego, CA
Posts: 405
|
Dunno, haven't tried it.
I assume you are maintaining state in your object. So, why not just call ScheduleTimerWithTimeInterval, as you did originally? Your timerUpdate method would examine state to see which card to flip, and flip it.
You really should be organizing your app to asynchronously respond to events. The timer is just another event. In this case, it's telling you "time to flip another card!"
Imagine you put in a button, "Flip the next card". The only difference is, it's the timer telling you to flip the next card, not the button.
|
|
|
 |
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
» Advertisements |
» Online Users: 490 |
| 52 members and 438 guests |
| 3DTOPO, ackpth, AjohnB, Alchemda, alon7, amiralic, andrewjak, asimrs, bbc z, beginer2007, bixcoito, bluemonkey, BostonMerlin, BrianSlick, Centurion Games, cornishGeeza, crabFish, dany88, embedded, ggalante, gralem, greenuns, Gudus, healthyutech, iMoan, inwhatworld, IphoneSdk, itakenocrud, john855, JoshuaCaputo, Kalimba, MarkC, mebarron, MikeBlah, mlfarrell, mriphoneman, MrMattMac, msudan, muallin, Noise, Oliver Drobnik, PeddlePower, pereorra, pierrephi, pjklimtx, Pring, ryguy2503, StefanL, the1nz4ne, ustech001, wuf810, ZunePod |
| Most users ever online was 779, 05-11-2009 at 10:55 AM. |
» Stats |
Members: 21,510
Threads: 35,794
Posts: 156,817
Top Poster: smasher (2,449)
|
| Welcome to our newest member, dmf1978 |
|