• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: how to prevent TableView update on key repeat?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to prevent TableView update on key repeat?


  • Subject: Re: how to prevent TableView update on key repeat?
  • From: Quincey Morris <email@hidden>
  • Date: Thu, 03 May 2012 14:28:25 -0700

On May 3, 2012, at 13:46 , Marc Respass wrote:

> Can anyone point me in the right direction on this? How can I prevent tableViewSelectionDidChange: from being called when the user is holding the up or down arrow and trying to scroll rapidly through the table so I only update when they stop?

One approach is to move the heavyweight code out of your selectionDidChange method into a separate method, the invoke this new method via 'performSelector:…afterDelay:0' (or, maybe better still, 'afterDelay:0.1'). In order to prevent the performs from stacking up, you would always invoke 'cancelPreviousPerformRequestsWithTarget:selector:object:' first.

That is, you always write something like this pattern:

	[cancelPreviousPerformRequestsWithTarget: self selector: @selector (mySelectionDidChange:) object: nil];
	[self performSelector: @selector (mySelectionDidChange) withObject: nil afterDelay: 0.1];

so you have a queue of 0 or 1 pending selection change actions at any time, and the action is done "soon if not canceled first".

Other approaches are to use NSOperationQueue to schedule a separate operation, or GCD to schedule a separate block, to the same effect. With a bit more trouble and attention to thread safety, you could arrange for either of these to be done on a background thread, if performance considerations warrant the extra effort.


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: how to prevent TableView update on key repeat?
      • From: Marc Respass <email@hidden>
References: 
 >how to prevent TableView update on key repeat? (From: Marc Respass <email@hidden>)

  • Prev by Date: how to prevent TableView update on key repeat?
  • Next by Date: Re: Xcode warns about missing protocol definition, even though @protocol is used
  • Previous by thread: how to prevent TableView update on key repeat?
  • Next by thread: Re: how to prevent TableView update on key repeat?
  • Index(es):
    • Date
    • Thread