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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:57:29+00:00 2026-05-25T18:57:29+00:00

UIView has a setNeedsDisplay method that one can call several times within the same

  • 0

UIView has a setNeedsDisplay method that one can call several times within the same event loop, safe in the knowledge that the redrawing work will happen soon, and only the once.

Is there a generic mechanism for this sort of behaviour Cocoa? A way of of saying, “Queue a selector as many times as you like, when it’s time, the selector will run once & clear the queue.”

I know I could do this with some kind of state tracking in my target, or with an NSOperationQueue. I’m just wondering if there’s a lightweight approach I’ve missed.

(Of course, the answer may be, “No”.)

  • 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-25T18:57:30+00:00Added an answer on May 25, 2026 at 6:57 pm

    setNeedsDisplay is not a good example of what you’re describing, since it actually does run every time you call it. It just sets a flag. But the question is good.

    One solution is to use NSNotificationQueue with NSNotificationCoalescingOnName.

    Another solution is to build a trampoline to do the coalescing yourself. I don’t have a really good blog reference for trampolines, but here’s an example of one (LSTrampoline). It’s not that hard to build this if you want to coalesce the messages over a period of time. I once built a trampoline with a forwardInvocation: similar to this:

    - (void)forwardInvocation:(NSInvocation *)invocation {
      [invocation setTarget:self.target];
      [invocation retainArguments];
      [self.timer invalidate];
      self.timer = [NSTimer scheduledTimerWithTimeInterval:self.timeout invocation:invocation repeats:NO];
    }
    

    This actually coalesces all messages to the object over the time period (not just matching messages). That’s all I needed for the particular problem. But you could expand on this to keep track of which selectors are being coalesced, and check your invocations to see if they match “sufficiently.”

    To get this to run on the next event loop, just set timeout to 0.

    I keep meaning to blog about trampolines. Required shilling: My upcoming book covers trampolines in Chapter 4 and Chapter 20.

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

Sidebar

Related Questions

I have a UIView that has several UIImageViews as subviews. Each of these subviews
I have a UIView container that has two UIImageView s inside it, one partially
A UIView has a SizeToFit method that will make the UIView fit all of
I made a subclass of UIView that has a fixed frame. So, can I
I want to have a UIView subclass that has a border image, but I
I made a UIView using Interface Builder with a top bar that has Cancel
I have a UIView subclass ( CustomView for purposes of this question) that has
I have a subview that has been added to my UIView. The idea is
I'm implementing a UIView's (UITableViewCell to be more exact) drawRect method. My view has
I would like to create a UIView has multiple UITextFields validates each one as

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.