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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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 01-17-2010, 11:47 PM   #1 (permalink)
Registered Member
 
Join Date: Nov 2009
Location: Orange County, California
Posts: 36
Send a message via AIM to ShayansMind Send a message via Skype™ to ShayansMind
Default 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
ShayansMind is offline   Reply With Quote
Old 01-17-2010, 11:54 PM   #2 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 13
Default

Quote:
Originally Posted by ShayansMind View Post
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
Electronicfun is offline   Reply With Quote
Old 01-17-2010, 11:56 PM   #3 (permalink)
Registered Member
 
Join Date: Nov 2009
Location: Orange County, California
Posts: 36
Send a message via AIM to ShayansMind Send a message via Skype™ to ShayansMind
Default Re:Try that

doesn't work
ShayansMind is offline   Reply With Quote
Old 01-17-2010, 11:59 PM   #4 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 13
Default

Quote:
Originally Posted by ShayansMind View Post
doesn't work
ill get back to you in a few min ill run some test
Electronicfun is offline   Reply With Quote
Old 01-18-2010, 12:04 AM   #5 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
Default

Code:
time.text = [NSString stringWithFormat:@"%.02f", mainInt];
This assumes that mainInt is actually a poorly-named float.
__________________
BriTer Ideas LLC - Code review, consulting, development. PM for pricing.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
BrianSlick is offline   Reply With Quote
Old 01-18-2010, 12:15 AM   #6 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 13
Default

you forgot to add time.text = [NSString stringWithFormat:@"%i"];
Electronicfun is offline   Reply With Quote
Old 01-18-2010, 12:28 AM   #7 (permalink)
Registered Member
 
Join Date: Nov 2009
Location: Orange County, California
Posts: 36
Send a message via AIM to ShayansMind Send a message via Skype™ to ShayansMind
Default Doesnt Work :(

doesnt work
ShayansMind is offline   Reply With Quote
Old 01-18-2010, 12:29 AM   #8 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
Default

Ok, I can see this is going to take forever.

What DOES it do? In what way does it not work?
__________________
BriTer Ideas LLC - Code review, consulting, development. PM for pricing.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
BrianSlick is offline   Reply With Quote
Old 01-18-2010, 12:36 AM   #9 (permalink)
Registered Member
 
Join Date: Nov 2009
Location: Orange County, California
Posts: 36
Send a message via AIM to ShayansMind Send a message via Skype™ to ShayansMind
Default what does it do

Quote:
Originally Posted by BrianSlick View Post
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
ShayansMind is offline   Reply With Quote
Old 01-18-2010, 12:39 AM   #10 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
Default

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?
__________________
BriTer Ideas LLC - Code review, consulting, development. PM for pricing.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
BrianSlick is offline   Reply With Quote
Old 01-18-2010, 12:47 AM   #11 (permalink)
Registered Member
 
Join Date: Nov 2009
Location: Orange County, California
Posts: 36
Send a message via AIM to ShayansMind Send a message via Skype™ to ShayansMind
Default what i saw

Quote:
Originally Posted by BrianSlick View Post
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
ShayansMind is offline   Reply With Quote
Old 01-18-2010, 12:51 AM   #12 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
Default

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?
__________________
BriTer Ideas LLC - Code review, consulting, development. PM for pricing.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
BrianSlick is offline   Reply With Quote
Old 01-18-2010, 12:53 AM   #13 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 11
Default

Quote:
Originally Posted by ShayansMind View Post
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]
atmel is offline   Reply With Quote
Old 01-18-2010, 12:54 AM   #14 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
Default

Quote:
Originally Posted by atmel View Post
3. change "mainInt + 0.01" => mainInt += 0.01;
*forehead smack*
I should have seen that. Good catch.
__________________
BriTer Ideas LLC - Code review, consulting, development. PM for pricing.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
BrianSlick is offline   Reply With Quote
Old 01-18-2010, 12:57 AM   #15 (permalink)
Registered Member
 
Join Date: Nov 2009
Location: Orange County, California
Posts: 36
Send a message via AIM to ShayansMind Send a message via Skype™ to ShayansMind
Default it says

Quote:
Originally Posted by BrianSlick View Post
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
ShayansMind is offline   Reply With Quote
Old 01-18-2010, 01:11 AM   #16 (permalink)
Registered Member
 
Join Date: Nov 2009
Location: Orange County, California
Posts: 36
Send a message via AIM to ShayansMind Send a message via Skype™ to ShayansMind
Default it works!

all i had to do was change mainInt to a float type instaed of an integer
thanks everyone!
ShayansMind is offline   Reply With Quote
Reply

Bookmarks

Tags
code, nsstring, nstimer, sdk, simple

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: 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
Powered by vBadvanced CMPS v3.1.0

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