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 6662485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:23:40+00:00 2026-05-26T02:23:40+00:00

In my iPhone app I got several places where I can do a [object

  • 0

In my iPhone app I got several places where I can do a

[object performSelector: withObject: afterDelay:]

call. All lead to the same method. Now, in that method I want to execute some code only on the latest call of it. If it was the first, I could just do [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(thisMethod) object:nil] and be sure it gets called once.

But, is there a way to tell if there are any other method calls waiting to be executed?

I could use a counter in this class that I would increment each time I set this perform after delay, then decrement it at start of each call and only execute the code if this counter is zeroed. But I’m wondering if it’s the best/acceptable approach…

  • 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-05-26T02:23:40+00:00Added an answer on May 26, 2026 at 2:23 am

    Well what you could do is this: anytime you call [object performSelector: withObject: afterDelay:] just add the line you mentioned above it. You could actually create a method that handles that for you. For example:

    - (void)performSelectorOnce:(SEL)selector withObject:(id)object afterDelay:(NSTimeInterval)delay
    {
        [NSObject cancelPreviousPerformRequestsWithTarget:object selector:selector object:object];
        [self performSelector:selector withObject:object afterDelay:delay];
    }
    

    and than where ever you use [object performSelector: withObject: afterDelay:] just replace it with [self performSelectorOnce: withObject: afterDelay:];

    If you want to use this in multiple objects than you could actually create an NSObject category and add the method there.

    Let me know if this works for you.

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

Sidebar

Related Questions

I'm writing my first iphone app and through several examples I've got a UITableView
For my iPhone app I got to convert NSDate object to string, and then
I have created a small iPhone app using MonoTouch - got all provisioning files
I've got an iPhone App that is supposed to send POST data to my
I'm building an iphone app and I've got a table view with some textfields
On an iPhone App, I've got a custom keyboard which works like the standard
every iPhone and iPod Touch has got the Apple Addresses App ... when you
my iphone app crashes unexpectedly and looking at the crash log I can't tell
I've got an iPhone app that runs on the device. Now I need to
I've got an iPhone app that's mainly targetting 3.0, but which takes advantage of

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.