PDA

View Full Version : NSTimer HELP




Michael H
Nov 19, 2009, 10:33 AM
:confused: Error & Warning fixed, however when I Build & Go app loads ok but flipToSecond method doesn't seem to be called. I placed an NSLog in flipToSecond method to check if it is being called NO LUCK.

-(void) applicationDidFinishLaunching : (UIApplication *) application {

timer = [NSTimer scheduledTimerWithTimeInterval: 1.0 target:self selector:@selector(flipToSecond:) userInfo:nil repeats: NO]; // change YES to NO

}

//define the targetmethod

- (void) flipToSecond: (NSTimer *) timer {

NSLog(@"flipToSecond was successful!");

}

Last line in console is:

Pending breakpoint 1 - "objc_exception_throw" resolved
(gdb)

Can't seem to figure it out. Help Please.



kainjow
Nov 19, 2009, 11:17 AM
Do you get any warnings when compiling? What does the debugger show when it breaks on the exception?

dejo
Nov 19, 2009, 11:22 AM
How is timer declared?

PhoneyDeveloper
Nov 19, 2009, 11:36 AM
Non-repeating timing actions can usually be more simply implemented with performSelector:withObject:afterDelay:

Michael H
Nov 19, 2009, 12:03 PM
timer declared in .h file

#import <UIKit/UIKit.h>

@interface FirstViewController : UIViewController {

NSTimer *timer;

}

@property (nonatomic, retain) NSTimer *timer;


@end

Debugger indicates build successful.

Am I missing something on starting the loop?

dejo
Nov 19, 2009, 12:09 PM
applicationDidFinishLaunching: is an application delegate method; it won't be called on your FirstViewController.

Michael H
Nov 19, 2009, 07:57 PM
THANKS so much everyone for your help.

-(void)viewDidLoad {

[self performSelector: @selector(flipToSecond:) withObject: nil afterDelay: 3.0];

[super viewDidLoad];
}

Used performSelector instead of NSTimer and placed it in viewDidLoad instead of applicationDidFinishLaunching.

I've learned a lot from everyone and again thank all of you.

dejo
Nov 20, 2009, 10:39 AM
Here's a bit more help: make sure you use the code tags when including code snippets. This sticky has more details: Posting code, please use the [CODE] tags (http://forums.macrumors.com/showthread.php?t=747660)

Michael H
Nov 20, 2009, 07:51 PM
Thanks I didn't know about the code tags