Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9324855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T04:42:12+00:00 2026-06-19T04:42:12+00:00

i am pretty much a noob here , and even writing the title was

  • 0

i am pretty much a noob here , and even writing the title was pretty hard …but here goes

I am trying to get my app to do this
1) user presses a button
2) the button converts the press to an int value
3) the value is then passed to NStimer and the timer counts until the int value is reached ( ie 30 secs if int value is 30
4) the program changes the image on the screen

I have got it to fire off the NStimer and change the screen by using a variable button and by changing this value manually i can set the timer to go off after different times

What i cant do is to get the timer to fire after the value is changed by the pressing of the button.
If i use NSLog i can see the value is changing but doesnt affect NSTimer….any ideas

Sorry if thats a bit long winded ,but here is the code…
Any help would be awesome…as i have lost most of my hair trying to work this out with do while loops and if statements

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
{
    UIImageView *theImage;
    int imageCount;
    int button;
    button = 10;
}

@property (strong, nonatomic) IBOutlet UIImageView *theImage;
@property (strong, nonatomic) IBOutlet UIButton *press;


@end

//
//  ViewController.m
//  use ns timer to display an image
//
//  Created by Clive Dancey on 19/02/2013.
//  Copyright (c) 2013 Clive Dancey. All rights reserved.
//

#import "ViewController.h"



@interface ViewController ()

@property (strong, nonatomic) IBOutlet UILabel *label1;


@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    [NSTimer scheduledTimerWithTimeInterval:button
                                     target:self
                                     selector:@selector(animateFunction)
                                     userInfo:nil
                                     repeats:YES];
}

- (IBAction)press:(id)sender
{
    button = 1;
}

- (void)animateFunction
{
    NSLog(@"Timer heartbeat %i", button);
    NSString *imageName = [NSString stringWithFormat:@"EZDecline.png"];
    [_theImage setImage:[UIImage imageNamed:imageName]];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T04:42:14+00:00Added an answer on June 19, 2026 at 4:42 am

    Ok I got you,

    1) remove this from viewDidLoad

    [NSTimer scheduledTimerWithTimeInterval:button
                                 target:self
                                 selector:@selector(animateFunction)
                                 userInfo:nil
                                 repeats:YES];
    

    2) Add this line to .h file

    @property (nonatomic, strong) NSTimer *myTimer;
    

    3) Change the code in your button press event, (like this)

    - (IBAction)press:(id)sender {
    button=1;
    if(_myTimer) [_myTimer invalidate];
    _myTimer = [NSTimer scheduledTimerWithTimeInterval:button
                                 target:self
                                 selector:@selector(animateFunction)
                                 userInfo:nil
                                 repeats:YES];
    

    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Pretty much the same as this question. But I can't seem to get this
I hope someone can help me here. I'm pretty much a noob trying to
this is pretty much a noob question but i can't find a solution. I'm
Title pretty much describes it, I just need to get all the order numbers
Sorry, I am pretty much an SQL noob. This has to work in MSFT
I'm pretty much a noob when it comes to javascript, but I wanted to
I gotta admit, I am pretty much a noob, but I have been struggling
Pretty much in in the title. Have seen this around and after a bit
Pretty much everything is in the title here. I have an android tablet, a
I'm not really too sure how to title this question, but I'm trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.