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 03-13-2011, 08:39 PM   #1 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 5
noobCoder is on a distinguished road
Default NSTimer problem

Hi all,

I have a quick problem I am hoping somebody could help me with, I am trying to refresh a view background at a User determined speed through the use of an NSTimer.

I have a TextView that you can enter a value, I then convert this to an integer and pass it to the NSTimer which in turn calls a method which updates the background as follows.

timerBackground = [NSTimer scheduledTimerWithTimeInterval:TEXTVIEWVALUE
target:self
selector:@selector(methodCall)
userInfo:nil
repeats:YES];

but the value I am trying to set seems sporadic and not updating at a speed which it should be.

Anybody see what I am doing wrong?

Thanks
noobCoder is offline   Reply With Quote
Old 03-13-2011, 09:16 PM   #2 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by noobCoder View Post
Hi all,

I have a quick problem I am hoping somebody could help me with, I am trying to refresh a view background at a User determined speed through the use of an NSTimer.

I have a TextView that you can enter a value, I then convert this to an integer and pass it to the NSTimer which in turn calls a method which updates the background as follows.

timerBackground = [NSTimer scheduledTimerWithTimeInterval: TEXTVIEWVALUE
target:self
selector:@selector(methodCall)
userInfo:nil
repeats:YES];

but the value I am trying to set seems sporadic and not updating at a speed which it should be.

Anybody see what I am doing wrong?

Thanks
The code you posted looks fine, ignoring some style issues.

Why don't you add a log statement to display the value of TEXTVIEWVALUE before you set up the timer:

Code:
NSLog(@"Timer value = %f", (float) TEXTVIEWVALUE);
timerBackground = [NSTimer scheduledTimerWithTimeInterval: TEXTVIEWVALUE
                                                      target:self
                                                      selector:@selector(methodCall)
                                                      userInfo:nil
                                                      repeats:YES];
Time intervals are floating point values expressed in seconds.
By the way, Cocoa variable names begin with a lower case letter by convention. Then the first letter of each word in a variable name is usually capitalized.

Labels that begin with upper case are supposed to be class names. Most people use all upper case for constants.

So your variable name should be "textViewValue".
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 03-13-2011, 10:34 PM   #3 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 5
noobCoder is on a distinguished road
Default

Thanks for your reply Duncan.

I just had the fields in all uppercase to show what I had changed from the original template the NSTimer function gives.

I am outputting to the Log file and the float value seems to be always assigned 0.0 which seems strange.
noobCoder is offline   Reply With Quote
Old 03-13-2011, 10:48 PM   #4 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by noobCoder View Post
Thanks for your reply Duncan.

I just had the fields in all uppercase to show what I had changed from the original template the NSTimer function gives.

I am outputting to the Log file and the float value seems to be always assigned 0.0 which seems strange.

So your bug is elsewhere than the code you posted. Work your way back and figure out why you're not getting the value you expect.

BTW, I suggest using the bold tag in the message editor to mark code rather than upper-casing it. C code is case-sensitive, after all. I wish it wasn't, but there you go.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 03-14-2011, 07:00 PM   #5 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 5
noobCoder is on a distinguished road
Default

After going back through the code I have found that the integer value seems to always be assigned to a really high number i.e. around 18000, when in theory I am only writing the numbers 1 through 10 in the text box for testing. Starting to baffle me a little.

I will persist with another approach though. Thanks for your help so far




Since going through my code I have found the answer out, Thanks again for your help

Last edited by noobCoder; 03-14-2011 at 07:12 PM. Reason: Conclusion found
noobCoder is offline   Reply With Quote
Old 03-14-2011, 08:08 PM   #6 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by noobCoder View Post
After going back through the code I have found that the integer value seems to always be assigned to a really high number i.e. around 18000, when in theory I am only writing the numbers 1 through 10 in the text box for testing. Starting to baffle me a little.

I will persist with another approach though. Thanks for your help so far




Since going through my code I have found the answer out, Thanks again for your help
Sounds like a type mismatch problem. Try casting your value to a double before passing it to the NSTimer.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Reply

Bookmarks

Tags
nstimer, textfield, uitextfield

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: 359
9 members and 350 guests
Absentia, akphyo, apatsufas, BinHex, fredidf, iGamesDev, Kirkout, MarkC, mottdog
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,667
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, host number one
Powered by vBadvanced CMPS v3.1.0

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