Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.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 08-05-2010, 10:59 PM   #1 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 10
doopster is on a distinguished road
Unhappy Timer Help

Hi. Ive been making a game and for some reason instead of this number counting down by 1 its been counting down by 4. Here is my code below:
Code:
- (IBAction)count:(id)sender {
    myTimer = 60;
    myTicker = [NSTimer scheduledTimerWithTimeInterval: 0.5 target: self selector: @selector(showActivity) userInfo: nil repeats: YES];
}
- (void)showActivity {
    myTimer = myTimer-1;
    text.text=[NSString stringWithFormat:@"%i", myTimer];
}
Please Help
doopster is offline   Reply With Quote
Old 08-06-2010, 01:45 AM   #2 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 577
Speed is on a distinguished road
Default

Quote:
Originally Posted by doopster View Post
Hi. Ive been making a game and for some reason instead of this number counting down by 1 its been counting down by 4. Here is my code below:
Code:
- (IBAction)count:(id)sender {
    myTimer = 60;
    myTicker = [NSTimer scheduledTimerWithTimeInterval: 0.5 target: self selector: @selector(showActivity) userInfo: nil repeats: YES];
}
- (void)showActivity {
    myTimer = myTimer-1;
    text.text=[NSString stringWithFormat:@"%i", myTimer];
}
Please Help
Why are you calling showActivity every 0.5 seconds? If it is a timer, wouldn't you want it calling every second? I would set it up personally as:

Code:
-(void)someMethod {

myTimer = 60;
myTicker = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(showActivity) userInfo:nil repeats:YES];

}

-(void)showActivity {

myTimer = myTimer - 1;
textView.text = [NSString stringWithFormat:@"%d",myTimer];

}
Declare myTicker as an NSTimer and myTimer as an integer.

Code:
int myTimer;
NSTimer *myTicker;
Speed is offline   Reply With Quote
Old 08-06-2010, 06:18 AM   #3 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 10
doopster is on a distinguished road
Post

I tried that code and its still Counts down by 4 (e.g 60, 56, 52 )
doopster is offline   Reply With Quote
Old 08-06-2010, 09:39 AM   #4 (permalink)
Pro. Game Developer
iPhone Dev SDK Supporter
 
Join Date: Feb 2009
Location: żLa Islas Hermosas?
Posts: 2,176
Kalimba is on a distinguished road
Default

The most common cause for a "timer value" to count by 4's is that it's incorrectly declared as "int *", rather than just "int". Double-check the declaration in your class interface.
__________________
~~ Word Flurry ~~ App Store / Website / Facebook
Kalimba is offline   Reply With Quote
Old 08-06-2010, 07:01 PM   #5 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 10
doopster is on a distinguished road
Smile

Thank you, that worked! I had "int *myTimer" instead of "int myTimer"
THANKYOU!!!!
doopster is offline   Reply With Quote
Old 08-06-2010, 09:12 PM   #6 (permalink)
Pro. Game Developer
iPhone Dev SDK Supporter
 
Join Date: Feb 2009
Location: żLa Islas Hermosas?
Posts: 2,176
Kalimba is on a distinguished road
Default

Quote:
Originally Posted by doopster View Post
Thank you, that worked! I had "int *myTimer" instead of "int myTimer"
THANKYOU!!!!
For the record, this is what Speed suggested two posts before mine, and you said that you tried it and it didn't work... :/
__________________
~~ Word Flurry ~~ App Store / Website / Facebook
Kalimba is offline   Reply With Quote
Old 08-07-2010, 08:13 AM   #7 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 10
doopster is on a distinguished road
Post My bad

Woops I didn't notice that there was no * on Speeds post. I thought that it had it. There for My Bad. I guess that speeds post did solve the problem. And that you just kind of showed me what I missed.

So thankyou to you both!
doopster is offline   Reply With Quote
Reply

Bookmarks

Tags
counting, nstimer, uilabel

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



» Advertisements
» Online Users: 305
11 members and 294 guests
alexP, arash5500, gordo26, HemiMG, linkmx, mediaspree, nobstudio, Objective Zero, Sloshmonster, stanny, Touchmint
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,655
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, pungs
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:28 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0