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

  • Home
  • SEARCH
  • 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 8394469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:04:16+00:00 2026-06-09T20:04:16+00:00

How do i set up a button (IBAction and UIButton attached) to continue to

  • 0

How do i set up a button (IBAction and UIButton attached) to continue to run the IBAction or a function while the button is being pressed, running a functioning continuously until the button is let up.

Should i attach a value changed receiver?

Simple question, but I can’t find the answer.

  • 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-09T20:04:17+00:00Added an answer on June 9, 2026 at 8:04 pm

    Add a dispatch source iVar to your controller…

    dispatch_source_t     _timer;
    

    Then, in your touchDown action, create the timer that fires every so many seconds. You will do your repeating work in there.

    If all your work happens in UI, then set queue to be

    dispatch_queue_t queue = dispatch_get_main_queue();
    

    and then the timer will run on the main thread.

    - (IBAction)touchDown:(id)sender {
        if (!_timer) {
            dispatch_queue_t queue = dispatch_get_global_queue(
                DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
            _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
            // This is the number of seconds between each firing of the timer
            float timeoutInSeconds = 0.25;
            dispatch_source_set_timer(
                _timer,
                dispatch_time(DISPATCH_TIME_NOW, timeoutInSeconds * NSEC_PER_SEC),
                timeoutInSeconds * NSEC_PER_SEC,
                0.10 * NSEC_PER_SEC);
            dispatch_source_set_event_handler(_timer, ^{
                // ***** LOOK HERE *****
                // This block will execute every time the timer fires.
                // Do any non-UI related work here so as not to block the main thread
                dispatch_async(dispatch_get_main_queue(), ^{
                    // Do UI work on main thread
                    NSLog(@"Look, Mom, I'm doing some work");
                });
            });
        }
    
        dispatch_resume(_timer);
    }
    

    Now, make sure to register for both touch-up-inside and touch-up-outside

    - (IBAction)touchUp:(id)sender {
        if (_timer) {
            dispatch_suspend(_timer);
        }
    }
    

    Make sure you destroy the timer

    - (void)dealloc {
        if (_timer) {
            dispatch_source_cancel(_timer);
            dispatch_release(_timer);
            _timer = NULL;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an IBAction that displays what is being pressed on certain buttons to
I've set my button to 'Submit'. The XPage is set to stay on the
Possible Duplicate: Android Button: set onClick background image change with XML? I need that
I have an EditText and a Button set next to each other on the
All right so I tried using the button set. So fair, I have been
I noticed that the height of a TToolButton increases when you set the button's
I am coding a quiz module, which contains a radio button set, using jQuery
So i have a UIScrollview with UIImageView set with a button, I want to
I do get that we easily can set the Close button text to a
This is my activity oncreate() method. I set a positive button ok with a

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.