01-17-2010, 11:47 PM
#1 (permalink )
Registered Member
Join Date: Nov 2009
Location: Orange County, California
Posts: 36
NSTimer Help!
Okay, hello
so am Trying to build an app where there is a uilabel and a button when u tap the button the label counts up by seconds and milliseconds
basically the label should be 0.00 (seconds.milliseconds)
how can i make a simple action and timer that do this my code won't work
code:
-(IBAction)start {
mainInt = 0;
myTime = [NSTimer scheduledTimerWithTimeInterval:0.01f target:self selector:@selector(randomMainVoid) userInfo:nil repeats:YES];
}
-(IBAction)stop {
[myTime invalidate];
}
-(IBAction)reset {
time.text = @"0.00";
}
-(void)randomMainVoid {
mainInt + 0.01;
time.text = [NSString stringWithFormat:@"0.00", mainInt];
}
someone please help me,
I am fairly new to the SDK
01-17-2010, 11:54 PM
#2 (permalink )
Registered Member
Join Date: Dec 2009
Posts: 13
Quote:
Originally Posted by
ShayansMind
Okay, hello
so am Trying to build an app where there is a uilabel and a button when u tap the button the label counts up by seconds and milliseconds
basically the label should be 0.00 (seconds.milliseconds)
how can i make a simple action and timer that do this my code won't work
code:
-(IBAction)start {
mainInt = 0;
myTime = [NSTimer scheduledTimerWithTimeInterval:0.01f target:self selector:@selector(randomMainVoid) userInfo:nil repeats:YES];
}
-(IBAction)stop {
[myTime invalidate];
}
-(IBAction)reset {
time.text = @"0.00";
}
-(void)randomMainVoid {
mainInt + 0.01;
time.text = [NSString stringWithFormat:@"0.00", mainInt];
}
someone please help me,
I am fairly new to the SDK
first try taking the f after 0.01 in
Quote:
-(IBAction)start {
mainInt = 0;
myTime = [NSTimer scheduledTimerWithTimeInterval:0.01f target:self selector:@selector(randomMainVoid) userInfo:nil repeats:YES];
try that
01-17-2010, 11:56 PM
#3 (permalink )
Registered Member
Join Date: Nov 2009
Location: Orange County, California
Posts: 36
Re:Try that
doesn't work
01-17-2010, 11:59 PM
#4 (permalink )
Registered Member
Join Date: Dec 2009
Posts: 13
Quote:
Originally Posted by
ShayansMind
doesn't work
ill get back to you in a few min ill run some test
01-18-2010, 12:04 AM
#5 (permalink )
Emphasizing Fundamentals
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
Code:
time.text = [NSString stringWithFormat:@"%.02f ", mainInt];
This assumes that mainInt is actually a poorly-named float.
01-18-2010, 12:15 AM
#6 (permalink )
Registered Member
Join Date: Dec 2009
Posts: 13
you forgot to add time.text = [NSString stringWithFormat:@"%i"];
01-18-2010, 12:28 AM
#7 (permalink )
Registered Member
Join Date: Nov 2009
Location: Orange County, California
Posts: 36
Doesnt Work :(
doesnt work
01-18-2010, 12:29 AM
#8 (permalink )
Emphasizing Fundamentals
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
Ok, I can see this is going to take forever.
What DOES it do? In what way does it not work?
01-18-2010, 12:36 AM
#9 (permalink )
Registered Member
Join Date: Nov 2009
Location: Orange County, California
Posts: 36
what does it do
Quote:
Originally Posted by
BrianSlick
Ok, I can see this is going to take forever.
What DOES it do? In what way does it not work?
ok its simple i want a button and a label when you tap the button the label counts in this format 0.00 (seconds:milliseconds) how do i this i know u dont work for free, if you help me i will mention you on this site: iphoneapptuts.com
it gets alot of visitors and ill give u shoutout on my next videos
please I really need help on this
01-18-2010, 12:39 AM
#10 (permalink )
Emphasizing Fundamentals
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
No, I'm not asking you how it is supposed to work. I get that.
I'm asking you what it is actually doing. You run the app. You see something. What you see is not what you wanted. What did you see?
01-18-2010, 12:47 AM
#11 (permalink )
Registered Member
Join Date: Nov 2009
Location: Orange County, California
Posts: 36
what i saw
Quote:
Originally Posted by
BrianSlick
No, I'm not asking you how it is supposed to work. I get that.
I'm asking you what it is actually doing. You run the app. You see something. What you see is not what you wanted. What did you see?
listen dude, i saw my label not doing anything when i click the button the label can only count in 1 second by second i need a stopwatch kind of thing
i will be on for ten mins then again on tommarrow
01-18-2010, 12:51 AM
#12 (permalink )
Emphasizing Fundamentals
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
Code:
-(void)randomMainVoid {
mainInt + 0.01;
NSLog(@"mainInt is: %.02f", mainInt");
time.text = [NSString stringWithFormat:@"%.02f ", mainInt];
}
Add that. What does it say when you run it?
01-18-2010, 12:53 AM
#13 (permalink )
Registered Member
Join Date: Sep 2009
Posts: 11
Quote:
Originally Posted by
ShayansMind
Okay, hello
so am Trying to build an app where there is a uilabel and a button when u tap the button the label counts up by seconds and milliseconds
basically the label should be 0.00 (seconds.milliseconds)
how can i make a simple action and timer that do this my code won't work
code:
-(IBAction)start {
mainInt = 0;
myTime = [NSTimer scheduledTimerWithTimeInterval:0.01f target:self selector:@selector(randomMainVoid) userInfo:nil repeats:YES];
}
-(IBAction)stop {
[myTime invalidate];
}
-(IBAction)reset {
time.text = @"0.00";
}
-(void)randomMainVoid {
mainInt + 0.01;
time.text = [NSString stringWithFormat:@"0.00", mainInt];
}
someone please help me,
I am fairly new to the SDK
hello,
you need modify following:
1. declare mainInt as float type: float mainInt ;
2. in reset() method: add mainInt = 0.0;
3. change "mainInt + 0.01" => mainInt += 0.01;
4. change time.text = [NSString stringWithFormat:@"0.00", mainInt]
=> time.text = [NSString stringWithFormat:@"%.2f", mainInt]
01-18-2010, 12:54 AM
#14 (permalink )
Emphasizing Fundamentals
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
Quote:
Originally Posted by
atmel
3. change "mainInt + 0.01" => mainInt += 0.01;
*forehead smack*
I should have seen that. Good catch.
01-18-2010, 12:57 AM
#15 (permalink )
Registered Member
Join Date: Nov 2009
Location: Orange County, California
Posts: 36
it says
Quote:
Originally Posted by
BrianSlick
Code:
-(void)randomMainVoid {
mainInt + 0.01;
NSLog(@"mainInt is: %.02f", mainInt");
time.text = [NSString stringWithFormat:@"%.02f ", mainInt];
}
Add that. What does it say when you run it?
mainInt = 0.0 when i run the code but the label doesn't change to like 0.01 etc
01-18-2010, 01:11 AM
#16 (permalink )
Registered Member
Join Date: Nov 2009
Location: Orange County, California
Posts: 36
it works!
all i had to do was change mainInt to a float type instaed of an integer
thanks everyone!
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: 285
18 members and 267 guests
2WeeksToGo , ADY , Creativ , dacapo , Dani77 , Fritzer , ghost , HDshot , headkaze , iDifferent , mer10 , mystic.purple , Rudy , smethorst , stoneage , superg , tathaastu , Zool
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,878
Threads: 89,224
Posts: 380,732
Top Poster: BrianSlick (7,129)
Welcome to our newest member, olga2000