Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

iVidCam Free
(free)

Kid Art
($0.99)

iPUBQUIZ
(£1.19)

ArtStudio
($3.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 04-25-2009, 07:16 PM   #1 (permalink)
Registered Member
 
Join Date: Mar 2009
Posts: 161
Default 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
will.ray is offline   Reply With Quote
Old 04-25-2009, 07:34 PM   #2 (permalink)
New Member
 
Join Date: Jan 2009
Location: San Diego, CA
Posts: 405
Default

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 07:36 PM.
jtara is offline   Reply With Quote
Old 04-25-2009, 07:47 PM   #3 (permalink)
Registered Member
 
Join Date: Mar 2009
Posts: 161
Default

Quote:
Originally Posted by jtara View Post
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?
will.ray is offline   Reply With Quote
Old 04-25-2009, 09:51 PM   #4 (permalink)
New Member
 
Join Date: Jan 2009
Location: San Diego, CA
Posts: 405
Default

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.
jtara is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Online Users: 256
21 members and 235 guests
bbc z, benoitr007, bluelobster, cparker101, csnplt, donbhar, dre, georgeburns, icordoba, iTrackiGiveaway, MrMattMac, numnEsoff, Nuncha, pcgeek, penjettti, Sara Paul, scotopia, SecurityAVZ, shan, _nivek
Most users ever online was 779, 05-11-2009 at 09:55 AM.
» Stats
Members: 24,268
Threads: 39,062
Posts: 171,293
Top Poster: smasher (2,575)
Welcome to our newest member, SecurityAVZ
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:16 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0