performSelector unable to run while UITableView is dragged?
Hi all,
I have a UITableViewController with its default UITableView. I begin slowly dragging the table with my finger to scroll, i.e. not flicking it with my finger. Every time the table moves on-screen the scrollViewDidScroll method of the controller is called; when some conditions I've specified are met, one of these calls to scrollViewDidScroll uses performSelector:withObject:afterDelay to schedule some action at a later time.
However, I'm finding that the action will not execute until I release my finger. For example, if I set the afterDelay parameter to 2 seconds, but hold my finger for 5 seconds, when I release my finger and the action executes it's 3 seconds too late. Is there any way to allow the action (which is to update the UI and so must run in the main thread) to execute while the finger is still against the screen?
I have a UITableViewController with its default UITableView. I begin slowly dragging the table with my finger to scroll, i.e. not flicking it with my finger. Every time the table moves on-screen the scrollViewDidScroll method of the controller is called; when some conditions I've specified are met, one of these calls to scrollViewDidScroll uses performSelector:withObject:afterDelay to schedule some action at a later time.
However, I'm finding that the action will not execute until I release my finger. For example, if I set the afterDelay parameter to 2 seconds, but hold my finger for 5 seconds, when I release my finger and the action executes it's 3 seconds too late. Is there any way to allow the action (which is to update the UI and so must run in the main thread) to execute while the finger is still against the screen?
Thanks!
The whole point of performSelector:withObject:afterDelay: is that it sets up a call to occur after your code returns to the main event loop.
If you run code in a tight loop that doesn't allow the event loop to run, the method doesn't get called until your code returns. It sounds like the scroll view keeps the app in a loop handling the user drag action until release. That surprises me, since the scroll view needs to handle touchesMoved events. Nevertheless, the answer is that you can't use performSelector:withObject:afterDelay:
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
While you are scrolling the event loop runs in NSEventTrackingRunLoopMode, and will not trigger normal timer events and performSelectors. This is done to keep the UI snappy.
You can create an NSTimer that will run in that loop though, by creating and scheduling it yourself. See the addTimer answer to this question:
While you are scrolling the event loop runs in NSEventTrackingRunLoopMode, and will not trigger normal timer events and performSelectors. This is done to keep the UI snappy.
You can create an NSTimer that will run in that loop though, by creating and scheduling it yourself. See the addTimer answer to this question: