NSTimer HELP

Discussion in 'iPhone/iPad Programming' started by Michael H, Nov 19, 2009.

  1. macrumors newbie

    Joined:
    Jan 26, 2008
    #1
    :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.
     
  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    Do you get any warnings when compiling? What does the debugger show when it breaks on the exception?
     
  3. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
    How is timer declared?
     
  4. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #4
    Non-repeating timing actions can usually be more simply implemented with performSelector:withObject:afterDelay:
     
  5. thread starter macrumors newbie

    Joined:
    Jan 26, 2008
    #5
    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?
     
  6. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    applicationDidFinishLaunching: is an application delegate method; it won't be called on your FirstViewController.
     
  7. thread starter macrumors newbie

    Joined:
    Jan 26, 2008
    #7
    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.
     
  8. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #8
  9. thread starter macrumors newbie

    Joined:
    Jan 26, 2008
    #9
    Thanks I didn't know about the code tags
     

Share This Page