 |
 |
|
 |
07-10-2009, 06:15 PM
|
#1 (permalink)
|
|
Registered Member
Join Date: May 2009
Posts: 12
|
Need help with timer
I need help trying to figure out how to declare my countDown thingy. I need to know how and where to declare it. can anyone help me? I followed the tutorial by Nitrex88 and I just omitted the animation part of the code. and i keep getting the " 'countDown' undeclared first use in function. " error. I've included the timer part of the .m file and the entire .h file.
Code:
//Timer
-(IBAction)timeStart {
time = 60.0;
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:(countDown) userInfo:nil repeats:YES]; <<<<ERROR HERE----
}
-(void) countDown {
time = time - 1;
if (timer == 0){
[timer invalidate];
}
[self updateTimeLabel];
}
-(void) updateTimeLabel {
timeLabel.text = [NSString stringWithFormat:@"%i Sec", time];
}
Here's my .h
Code:
@interface iTap_Really_FastViewController : UIViewController {
IBOutlet UILabel *timeLabel;
NSTimer *timer;
NSUInteger time;
IBOutlet UILabel *tapsLabel;
IBOutlet UIImageView *tapButton;
}
@property (nonatomic, retain) NSTimer *timer;
@property (nonatomic, retain) UILabel *timeLabel;
@property (nonatomic, retain) UILabel *tapsLabel;
@property (nonatomic, retain) UIImageView *tapButton;
-(void)updateLabelsFromTouches:(NSSet *)touches;
-(IBAction)timeStart;
-(void)countDown;
-(void)updateTimeLabel;
|
|
|
07-10-2009, 07:23 PM
|
#2 (permalink)
|
|
Senior Member
iPhone Dev SDK Supporter
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 2,449
|
The "selector:" parameters expects a selector, which you need to get with the "@selector" directive. Try this:
Code:
timer = [NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(countDown) // I added @selector() here
userInfo:nil repeats:YES];
Also, you want "if (time == 0)" not "if (timer == 0)" . You want to check your counter, not the timer object.
__________________
|
|
|
 |
| 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: 484 |
| 51 members and 433 guests |
| alexanderlonsky, alexstuckey, atsd, BobK, bravetarget, BrianSlick, CHV, coconnor, cribasoft, dany88, dhouse, Dorald, Erle, espinallab, ethanwa, fede, Gamer211, GhostDog, gomugroup, Gudus, intomo, itakenocrud, javaconvert, johnnybluejeans, KenPletzer, kjelleinar, leeus, lepetitapps, MarkC, MiniRobinho, msu, nibby, NicolasD, Noise, P2k, pbcbvba, robotcult, sayhong, scribouillard, seriessix, spark86, svjim, treazer, tturk, Vonswanko, wassupdoc, winklllll, wooyaiz, x2on, ZunePod |
| Most users ever online was 779, 05-11-2009 at 10:55 AM. |
» Stats |
Members: 21,504
Threads: 35,785
Posts: 156,780
Top Poster: smasher (2,449)
|
| Welcome to our newest member, itakenocrud |
|