iOS NSTimer HELP

Michael H

macrumors newbie
Original poster
Jan 26, 2008
22
0
: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.

Code:
-(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

Moderator emeritus
Jun 15, 2000
7,958
5
Do you get any warnings when compiling? What does the debugger show when it breaks on the exception?
 
Comment

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
Non-repeating timing actions can usually be more simply implemented with performSelector:withObject:afterDelay:
 
Comment

Michael H

macrumors newbie
Original poster
Jan 26, 2008
22
0
timer declared in .h file

Code:
#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?
 
Comment

Michael H

macrumors newbie
Original poster
Jan 26, 2008
22
0
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.
 
Comment
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.