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 09-13-2010, 04:01 PM   #1 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 12
Mixsiah is on a distinguished road
Default NSTimer problem

simulated in iOS4.1

My app takes RSS data and loads in a table.

If it loads once it's fine....BUT the problem starts when I use the NSTimer to autorefresh every 10 seconds, it closes the app and goes back to homescreen.

Any suggestions?

- (void)viewDidAppearBOOL)animated {
[super viewDidAppear:animated] ;

if([blogEntries count] == 0) {
[self refreshData] ;
}

reloadTimer = [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector (refreshData ) userinfo:nil repeats:YES] ;

}

- (void)refreshData{
NSString *blogAddress = @"http://twitter.com";
[self grabRSSFeed:blogAddress];
[blogTable reloadData];
}

- (void)viewWillDisappearBOOL)animated {
[reloadTimer invalidate] , reloadTimer = nil;
}
Mixsiah is offline   Reply With Quote
Old 09-13-2010, 04:15 PM   #2 (permalink)
Registered Member
 
lukeinjax's Avatar
 
Join Date: May 2010
Posts: 125
lukeinjax is on a distinguished road
Default

If you comment out:

Code:
[blogTable reloadData];
does it still crash?

Your problem might be in your reloadData function, not the timer.

Also, I don't think this is valid syntax:

Code:
- (void)viewWillDisappearBOOL)animated {
[reloadTimer invalidate] , reloadTimer = nil;
}
Maybe a cut and paste error?
lukeinjax is offline   Reply With Quote
Old 09-13-2010, 04:34 PM   #3 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 12
Mixsiah is on a distinguished road
Default

hi

the refreshdata method is valid because I call that from an if statement and it works...


basically what i am trying to do is for the NSTimer to call the refreshdata method every 10 seconds....im a newbie so i might've made a syntax error somewhere....I studied and copied a lot of codes and still can't get it to work.

Maybe a cut and paste error?[/quote]...not sure about this either.


Please feel free to correct the code.
Mixsiah is offline   Reply With Quote
Old 09-13-2010, 05:22 PM   #4 (permalink)
Registered Member
 
lukeinjax's Avatar
 
Join Date: May 2010
Posts: 125
lukeinjax is on a distinguished road
Default

Quote:
Originally Posted by Mixsiah View Post
hi

the refreshdata method is valid because I call that from an if statement and it works...


basically what i am trying to do is for the NSTimer to call the refreshdata method every 10 seconds....im a newbie so i might've made a syntax error somewhere....I studied and copied a lot of codes and still can't get it to work.

Maybe a cut and paste error?
...not sure about this either.


Please feel free to correct the code.[/quote]

This should read:

Code:
- (void)viewWillDisappearBOOL)animated {
    [reloadTimer invalidate];
    reloadTimer = nil;
}
There might also be an issue with calling the refreshData method a second time - once in your if statement and again in the timer code. If that method is releasing something that's trying to be accessed the second time, that might be your issue.

Are there any messages in the console when your app crashes?
lukeinjax is offline   Reply With Quote
Old 09-13-2010, 05:36 PM   #5 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 12
Mixsiah is on a distinguished road
Default

Quote:
Originally Posted by lukeinjax View Post
...not sure about this either.


Please feel free to correct the code.
This should read:

Code:
- (void)viewWillDisappearBOOL)animated {
    [reloadTimer invalidate];
    reloadTimer = nil;
}
----DONE

There might also be an issue with calling the refreshData method a second time - once in your if statement and again in the timer code. If that method is releasing something that's trying to be accessed the second time, that might be your issue.


Are there any messages in the console when your app crashes?[/quote]

---I commented the if statement so it calls only the NSTimer in the viewDidLoad but it still displays this message:

NSTimer may not respond to '+scheduleTimerWithTimeInterval:target:selector:us erinfo:repeats


I watched all of the tutorials in youtube and its pretty simple. I copied it exactly.
Mixsiah is offline   Reply With Quote
Old 09-13-2010, 05:42 PM   #6 (permalink)
Registered Member
 
lukeinjax's Avatar
 
Join Date: May 2010
Posts: 125
lukeinjax is on a distinguished road
Default

I think I see your error.

Code:
reloadTimer = [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector (refreshData ) userinfo:nil repeats:YES] ;
should be:

Code:
reloadTimer = [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector (refreshData ) userInfo:nil repeats:YES] ;
Note the userInfo param. Case matters.

Also, see the "Timers" section of this page for an example:

iPhone SDK Examples
lukeinjax is offline   Reply With Quote
Old 09-13-2010, 05:45 PM   #7 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Quote:
Originally Posted by Mixsiah View Post
---I commented the if statement so it calls only the NSTimer in the viewDidLoad but it still displays this message:

NSTimer may not respond to '+scheduleTimerWithTimeInterval:target:selector:us erinfo:repeats
Try copy-pasting the method name out of the documentation. You have at least a couple of typos.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

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

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 09-13-2010, 05:54 PM   #8 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 12
Mixsiah is on a distinguished road
Default

By the way,

I started a new simple NSTimer project in a view based App

YouTube - Using a Timer in iPhone SDK

copied exactly the tutorial and it worked. All the code seem to be the same...



You think this has something to do that my app is reloading a table?
Mixsiah is offline   Reply With Quote
Old 09-13-2010, 05:58 PM   #9 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 12
Mixsiah is on a distinguished road
Default

SHARP EYES!!! ---userInfo corrected....IT WORKED!!

Thank you so much!
Mixsiah is offline   Reply With Quote
Reply

Bookmarks

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: 330
14 members and 316 guests
Absentia, cgokey, fiftysixty, givensur, heshiming, iGamesDev, linkmx, michaelhansen, mraalex, PixelInteractive, raihan.zbr, Sloshmonster, Trickphotostudios
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,117
Posts: 402,890
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

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