NSTimer/ BOOLs not working

Discussion in 'iOS Programming' started by Programmer, Oct 7, 2009.

  1. Programmer macrumors member

    Programmer

    Joined:
    Jun 16, 2009
    #1
    In my application I have a UIImageView and a Button over it. I have a button to start the animation which then Sets an ImageDidAppear BOOL to YES and starts a timer with the same length as the animation. When the timer goes off it sets the ImageDidAppear BOOL to NO. My button only responds if the BOOL = YES. The button stops the animation and also sets the ImageDidAppear BOOL to NO.

    The problem is that for some reason the Image shows up in the UIImageView but you can't tap the button to stop the animation or at least when you do hit it , it doesn't work.

    Help Please
     
  2. Kingbombs macrumors member

    Joined:
    Jun 24, 2009
    #2
    put a print command in there to check that you have atleast set up the IBAction to the button, so when you press it make sure the print command appears, then you are able to see where its most likly to be going wrong
     
  3. Programmer thread starter macrumors member

    Programmer

    Joined:
    Jun 16, 2009
    #3
    i'v tried that

    i've already tried that. and when i take out the timer it works fine but i need the timer to work for my application
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    Care to include some code snippets? Because I'm a little confused. If the button only responds if the BOOL == YES, but you "have a button to start the animation which then Sets an ImageDidAppear BOOL to YES", how can the BOOL ever get set to YES?
     
  5. Programmer thread starter macrumors member

    Programmer

    Joined:
    Jun 16, 2009
    #5
    Heres the code

    - (IBAction)Start {
    right1Appaered = YES;

    [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:mad:selector (right1) userInfo:nil repeats:NO];

    right1.animationImages = [NSArray arrayWithObjects:

    //Image Animation Here

    [right1 setAnimationRepeatCount:1];
    right1.animationDuration = speed;
    [right1 startAnimating];


    - (IBAction)right1 {
    if (right1Appaered) {
    right1Appaered = NO;
    Left1Appaered = YES;

    [right1 stopAnimating];


    }
    }
     
  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    So, you have one button that when you first tap it, starts the animation and then, while the animation is going, you want to tap the button again to stop the animation, is that correct?
     
  7. Programmer thread starter macrumors member

    Programmer

    Joined:
    Jun 16, 2009
    #7
    Sorry this is the code

    i forgot the closed curly bracket.

    - (IBAction)Start {
    right1Appaered = YES;

    [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:mad:selector (right1) userInfo:nil repeats:NO];

    right1.animationImages = [NSArray arrayWithObjects:

    //Image Animation Here

    [right1 setAnimationRepeatCount:1];
    right1.animationDuration = speed;
    [right1 startAnimating];

    }



    - (IBAction)right1 {
    if (right1Appaered) {
    right1Appaered = NO;
    Left1Appaered = YES;

    [right1 stopAnimating];

    }
    }
     
  8. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
  9. Programmer thread starter macrumors member

    Programmer

    Joined:
    Jun 16, 2009
  10. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #10
    And you're sure you have the second button connected to the right1 IBAction correctly in Interface Builder?
     
  11. Programmer thread starter macrumors member

    Programmer

    Joined:
    Jun 16, 2009
    #11
    yes

    yes i'm sure like i said everything works if i don't have the timer but i need the timer.
     
  12. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #12
    So, if you comment the timer out, then the second button calls the right1 method okay, but if it's included, right1 doesn't get called at all?
     
  13. Programmer thread starter macrumors member

    Programmer

    Joined:
    Jun 16, 2009
  14. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #14
    What happens if you give your UIImageView and your IBAction different names? Right now they are both right1. That's confusing (to me, at least, probably also to the compiler).
     
  15. Programmer thread starter macrumors member

    Programmer

    Joined:
    Jun 16, 2009
    #15
    It Worked?

    sorry it took so long to get back.

    I tried what you said and it worked but my question is why does that make the Timer work?
     
  16. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #16
    Seems the @selector is better able to resolve to the IBAction method
    and not the UIImageView, I suppose.
     

Share This Page